题目描述
Give you a number named N; please tell me how many ways to arrive N use two square
integers.
输入
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.
输出
If there is no way to arrive N use two square numbers, please output “No Solution!”, and
else output an integer indicating the ways number.
样例输入
50
9
样例输出
2
1
#include<stdio.h>
#include<string.h>
int hash[1000001];
int main()
{
int a,b;
for(a=0 ;a<=800 ;a++)
{
for(b=a;b<=1000;b++){
if(a*a+b*b<=1000000)
{
hash[a*a+b*b]++;
}
else
{
break;
}
}
}
int n;
while(scanf("%d",&n)!=EOF)
{
if(hash[n]==0)
{
printf("No Solution!\n");
}
else
{
printf("%d\n",hash[n]);
}
}
}