首页 > 代码库 > 黑龙江省赛The minimum square sum

黑龙江省赛The minimum square sum

题目

The minimum square sum

Time Limit 1000ms

Memory Limit 65536K

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

235							

sample_output

2185							

这道题其实不难关键是找到那个公式,如果那数字p,p=4k+1(2列外);则输出p;否则输出p*p*2;

#include<stdio.h>
int main()
{
    long long int i,j,k,n,m;
    
    while(scanf("%lld",&n)!=EOF)
    {
        if(n%4==1||n==2)
            printf("%lld\n",n);
        else
         
            printf("%lld\n",n*n*2);
 
     
 
    }
    return 0;
}

黑龙江省赛The minimum square sum