Sum of Square

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.

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值