Back to the Training Home
Back to the Training Home
Lesson: 34
Problem: 2526
Title: Root of the Problem
Difficulty Level: 2.0
Date: MAR 02, 2009
Site: http://acm.tju.edu.cn/toj/showp2526.html
Read the problem statement carefully. Very simple number theory problem.
#include<stdio.h>
#include<math.h>
int getResult(int b, int n) {
int k = (int)pow((double)b,(double)1/n);
int result1 = pow(k,n) - b;
int result2 = pow(k+1,n) - b;
if(result1 < 0) result1 *= -1;
if( result2 < 0) result2 *= -1;
return result1 > result2 ? k+1:k;
return 0;
}
int main() {
int b, n;
while(scanf("%d%d",&b,&n) == 2) {
if(!b && !n) break;
printf("%d\n",getResult(b,n));
}
return 0;
}
|