// Problem#: 1394
// Submission#: 3810734
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
int B,n;
while(cin >> B >> n&&(B!=0&&n!=0))
{
double s=1.0/n;
double a=pow(B,s);
int b=a;
int c=pow(b,n);
int d=pow(b+1,n);
if((B-c)>=(d-B))cout << b+1 << endl;
else cout << b << endl;
}
}
本文介绍了一种求解特定形式方程的整数解逼近算法,并通过代码实现了给定基数B和指数n的情况下,寻找最接近B的n次方根的整数解。该算法首先计算B的n次方根的浮点数解,然后向下取整得到一个整数b,再通过比较B与b的n次幂及b加1的n次幂之间的差距来决定最终的输出。
4766

被折叠的 条评论
为什么被折叠?



