Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接枚举b和p,手算b的p次方即可。。。int main() {int x; while(RI(x)!=EOF) { if(!x) break; int p=0; if(x>0) { for(int i=0;i<=65535;i++) {int tmp=1; for(int j=1;j<=31;j++) {tmp=tmp*i; if(tmp==x) { p=j; break; } if(tmp>x) break; } if(p!=0) break; } if(p==0) p=1; } else { for(int i=-1;i>=-65536;i--) { int tmp=1; for(int j=1;j<=31;j++) { tmp=tmp*i; if(tmp==x) { p=j; break; } if(tmp<x) break; } if(p!=0) break; } if(p==0) p=1; } printf("%d\n",p); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator