码迷,mamicode.com
首页 > 其他好文 > 详细

黑龙江省赛The minimum square sum

时间:2014-11-22 20:15:41      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:des   style   io   ar   color   os   sp   on   div   

题目

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

2
3
5
							

sample_output

2
18
5
							

这道题其实不难关键是找到那个公式,如果那数字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

标签:des   style   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/A458/p/4115541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!