假设 int 为 32 位有符号整数类型,输入的 n 是不超过 47000 的自然数、k 是不超过 int 表示范围的自然数,完成下面的判断题和单选题:
#include <iostream>
using namespace std;
int n,k;
int solve1()
{
int l=0,r=n;
while(l<=r) {
int mid = (l+r)/2;
if(mid * mid<=n)l=mid+1;
else r = mid-1;
}
return l-1;
}
double solve2(double x)
{
if (x == 0) return x;
for (int i = 0; i < k; i++)
x = (x + n / x) / 2;
return x;
}
int main()
{
cin>>n>>k;
double ans = solve2(solve1());
cout << ans << ' ' << (ans * ans == n) << endl;
return 0;
}
1
1.414
1.5
2
1.7
1.732
1.75
2