poj3100
来源:互联网 发布:淘宝奢侈品代购 编辑:程序博客网 时间:2024/04/29 21:01
http://poj.org/problem?id=3100
Description
Given positive integers B and N, find an integer A such thatAN is as close as possible to B. (The result A is anapproximation to the Nth root of B.) Note that AN may beless than, equal to, or greater than B.
Input
The input consists of one or more pairs of values for B and N.Each pair appears on a single line, delimited by a single space. Aline specifying the value zero for both B and N marks the end ofthe input. The value of B will be in the range 1 to 1,000,000(inclusive), and the value of N will be in the range 1 to 9(inclusive).
Output
For each pair B and N in the input, output A as defined above ona line by itself.
Sample Input
4 35 327 3750 51000 52000 53000 51000000 50 0
Sample Output
123444516
Source
long double pow(long double,int)
float pow(float,int)
double pow(double,int)
对于所给的参数int,int,编译器无法判断应该匹配哪个函数,因此报错
可以将代码改为pow(10.0,(int)i)
#include<stdio.h>#include<math.h>int main(){ int b,n; while(scanf("%d %d",&b,&n),b,n) { int i; for(i=1;i<=b;i++) { if(pow((float)i,(int)n)==b) { printf("%d\n",i); break; } else if(pow((float)i,(int)n)<b&&pow((float)i+1,(int)n)>b) { if(abs(pow((float)i,(int)n)-b)<abs(pow((float)i+1,(int)n)-b)) { printf("%d\n",i); break; } else { printf("%d\n",i+1); break; } } } } return 0;}