The minimum square sum | ||
| ||
description | ||
Given a prime p (p<108),you are to find min{x2+y2},where x and y belongs to positive integer, so that x2+y2=0 (mod p).
| ||
input | ||
Every line is a p. No more than 10001 test cases.
| ||
output | ||
The minimum square sum as described above.
| ||
sample_input | ||
2
3
5
| ||
sample_output | ||
2
18
5
| ||
hint | ||
| ||
source |
思路:结论p=4k+3则没有平方和会等于P,否则就有。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
long long p;
while (cin>>p)
{
if (p==2) cout << "2" << endl;
else if((p-3)%4==0) cout << 2*p*p << endl;
else cout << p << endl;
}
return 0;
}