首页 > 代码库 > poj 3100 && zoj 2818 ( Root of the Problem ) (睡前一水)
poj 3100 && zoj 2818 ( Root of the Problem ) (睡前一水)
链接:click here
题意:
Given positive integers B and N, find an integer A such that AN is as close as possible to B. (The result A is an approximation to the Nth root of B.) Note that AN may be less than, equal to, or greater than B.
.给你B和N,求个整数A使得A^n最接近B
不解释,代码:
//zoj 2818 poj 3100 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <math.h> using namespace std; int main() { double b,n; while(cin>>b>>n&&b&&n) { int a=(int )pow(b,1/n); //cout<<pow(a,n)<<endl; if(b-pow(a,n)<pow(a+1,n)-b) cout<<a<<endl; else cout<<a+1<<endl; } return 0; }
poj 3100 && zoj 2818 ( Root of the Problem ) (睡前一水)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。