Sum of Square
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 49 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Give you a number named N; please tell me how many ways to arrive N use two square integers.
Input
There are many of test cases. For each test case, just one line contains a number N (1<=N<=1000000).
Proceed to the end of file.
Proceed to the end of file.
Output
If there is no way to arrive N use two square numbers, please output “0”, and else output an integer indicating the ways number.
Sample Input
50 9
Sample Output
2 1 Hinds: There is two ways to arrive number 50: First: 50 = 1 + 49 Second: 50 = 25 + 25
#include <stdio.h> #include <string.h> const int n=1000010; int a[n],b[n]; int main() { memset(a,0,sizeof(a));memset(b,0,sizeof(b)); int i,j; for (i=0;i*i<=1000000;i++) a[i*i]=1; for (i=0;i<=1000;i++) { for (j=i;j*j<=1000000-i*i;j++) if (a[i*i]&&a[j*j]) b[i*i+j*j]++; } int N; while (scanf("%d",&N)!=EOF) { if (b[N]) printf ("%d\n",b[N]); else //printf ("0"); puts("0"); } 好像在codeblock里面运行会报错 但是VC6.0就不会 不知道为什么 return 0; }