Saturday 21 March 2009

POJ ( acm.pku.edu.cn ) 3100


本以为用 floor(pow(b,1./n)) 可以直接算出来——谁知道错了。



#include <iostream>
#include <cmath>
using namespace std;
inline int p(int a,int b){
for(int x=a;--b>0;a*=x);
return a;
}
int main() {
for(int b,n,i;cin>>b>>n&&b&&n;cout<<endl){
double x=floor(pow(b,1./n));
for(i=x;p(i,n)<b;++i);
if(p(i,n)-b>b-p(i-1,n))
cout<<i-1;
else
cout<<i;
}
return 0;
}

No comments:

Post a Comment