hdu 3835 简单概率dp

来源:互联网 发布:长笛 知乎 编辑:程序博客网 时间:2024/04/27 18:34

R(N)

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3   Accepted Submission(s) : 1
Problem Description
We know that some positive integer x can be expressed as x=A^2+B^2(A,B are integers). Take x=10 for example, 
10=(-3)^2+1^2.
We define R(N) (N is positive) to be the total number of variable presentation of N. So R(1)=4, which consists of 1=1^2+0^2, 1=(-1)^2+0^2, 1=0^2+1^2, 1=0^2+(-1)^2.Given N, you are to calculate R(N).
 

Input
No more than 100 test cases. Each case contains only one integer N(N<=10^9).
 

Output
For each N, print R(N) in one line.
 

Sample Input
26102565
 

Sample Output
4081216
Hint
For the fourth test case, (A,B) can be (0,5), (0,-5), (5,0), (-5,0), (3,4), (3,-4), (-3,4), (-3,-4), (4,3) , (4,-3), (-4,3), (-4,-3)
 
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int n;int main(){    while(scanf("%d",&n)!=EOF)    {        if(!n)        {            printf("1\n");            continue;        }        int i,j,ans=0,ave=(int)sqrt(double(n/2.0));        for(i=ave; i>=0; i--)        {             j=(int)sqrt(1.0*(n-i*i));                if(i*i+j*j==n)                {                    if(i==0||j==0||i==j) ans+=4;                    else ans+=8;                }        }        printf("%d\n",ans);    }    return  0;}/*26102565*/


Source
2011 Multi-University Training Contest 1 - Host by HNU
 
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 经常熬夜口气重怎么办 晚上睡不着白天起不来怎么办 晚上熬夜白天睡不着怎么办 在外打工孩子上学怎么办 婴儿脸干燥发红怎么办 宝宝脸上红点点怎么办 药流出血量少怎么办 药流喝药第一天发烧了怎么办 药流第一天量很少怎么办 小孩不想吃饭口臭怎么办 晚上上班白天睡不着怎么办 新车刮漆了怎么办 药流出血多怎么办 药流第二天没血怎么办 有异味怎么办%3f 养狗后悔了怎么办 买狗后悔了怎么办 小孩子不想去幼儿园怎么办 小孩子不想上幼儿园怎么办 想当兵视力不够怎么办 当兵裸眼视力差怎么办 去公司报道行李怎么办 报道第一天出糗怎么办 痛经一直想拉屎怎么办 月经第一天痛经怎么办 痛经痛得厉害怎么办 脑子里老是幻想怎么办 绿松石盘玩变黑怎么办 绿松石发乌了怎么办 泡脚泡的脚发黑怎么办 想当兵有纹身怎么办 小孩挨打不会还手怎么办 孩子挨打不敢还手怎么办 武警森林改革新兵怎么办 森林武警新兵后来怎么办 部队训练打死人怎么办? 部队受伤退伍后怎么办 60岁失地养老怎么办 梦遗到被子上怎么办 血管打针打的硬怎么办 征兵彩超不过怎么办?