您的位置:首页 > 其它

POJ 3100 && HDU 2740 Root of the Problem(水~)

2015-08-30 08:35 281 查看
Description

给你两个数n和g,求出最大a值使得a^g<=n

Input

多组用例,每组用例两个整数n和g,以0 0结束输入

Output

对于每组用例,求出满足条件的a值

Sample Input

4 3

5 3

27 3

750 5

1000 5

2000 5

3000 5

1000000 5

0 0

Sample Output

1

2

3

4

4

4

5

16

Solution

水题,pow的应用

Code

#include<stdio.h>
#include<math.h>
int main()
{
int n,g,a;
while(scanf("%d%d",&n,&g)&&n&&g)
{
a=1;
while(a++)
{
if((int)pow((double)a,g)>=n)
break;
}
a=(int)pow(a,g)-n>n-(int)pow(a-1,g)?a-1:a;
printf("%d\n",a);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: