http://acm.hdu.edu.cn/showproblem.php?pid=2740
题意:找到A,另A^N最接近B
思路:逆向考虑,B^(1/n)上下取整,在各取N次幂,看哪个更接近B
ps:注意上下取整
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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\n",q); else printf("%d\n",p); } return 0; }