HDU 2740 Root of the Problem
2499 ワード
http://acm.hdu.edu.cn/showproblem.php?pid=2740
标题:Aを見つけて、またA^NがBに一番近い
考え方:逆方向に考えて、B^(1/n)は上下に整頓して、それぞれN回のべき乗を取って、どれがもっとBに近いかを見ます
ps:上下に注意
View Code
标题:Aを見つけて、またA^NがBに一番近い
考え方:逆方向に考えて、B^(1/n)は上下に整頓して、それぞれN回のべき乗を取って、どれがもっとBに近いかを見ます
ps:上下に注意
View Code
#include <stdio.h>
#include <math.h>
int main()
{
int b,n;
double temp;
int p,q;
while(scanf("%d%d",&b,&n),(b||n))
{
temp=pow(b*1.0,1.0/n);
p=floor(temp);//
q=ceil(temp);//
if(b-pow(p,n)>pow(q,n)-b)
printf("%d
",q);
else
printf("%d
",p);
}
return 0;
}