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;
}