2429: Difference of Square Root
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| 3s | 8192K | 1161 | 147 | Standard |
At the previous problem , the difference of square is asked. This time, the square root is appeared.
Find minimal integer x that satified sqrt(x)-sqrt(y)=sqrt(n). y should be greater than zero.
Input and Output
For each integer n (n < 2^31) in one line of input, output the result x in one line.Sample Input
2 3
Sample Output
8 12
Problem Source: provided by skywind
This problem is used for contest: 93
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n;//n=a*a*b;
while(cin>>n)
{
long long a=(long long)sqrt(n+0.5);
for(;a>=1;a--)
{
if(n%(a*a)==0)
{
cout<<(a+1)*(a+1)*(n/a/a)<<endl;
break;
}
}
}
return 0;
}
本文介绍了一种算法,用于寻找最小整数x,使得sqrt(x) - sqrt(y) = sqrt(n),其中y > 0。文章给出了输入输出样例及对应的解决方案。
437

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



