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 |
测不动了!!!!!!!!!!!!!我这边用了整数处理,应该。。。。 #include <iostream> #include <cmath> using namespace std; #define in cin int getpow ( int v, int k ) { if ( k == 1 ) return v; else if ( k % 2 == 0 ) return getpow ( v, k / 2 ) * getpow ( v, k / 2 ); else return getpow ( v, k - 1 ) * v; } int main () { int n; while ( in >> n ) { if ( n == 0 ) break; int i = 1, result = -1, value; bool flag = true; if ( n < 0 ) { flag = false; n = -n; } while ( ( value = (int) pow ( n * 1.0, 1.0 / i) ) > 1 ) { if ( i > result && getpow ( value, i ) == n ) result = i; if ( flag ) i++; else i += 2; } cout << result << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator