hdu 3835:R(N)(水题,数学题)

R(N)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1815    Accepted Submission(s): 929


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
2 6 10 25 65
 

 

Sample Output
4 0 8 12 16
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)
 

 

Source
 

 

Recommend
xubiao   |   We have carefully selected several similar problems for you:  3833 3834 3832 3831 3830 

 
  水题,数学题
  题意是求一个正整数N分解成 N=A^2+B^2 的形式有多少种。A、B可以从0开始。
  思路:遍历即可,注意两层循环会超时,尽量用一层循环。用cin、cout不会超时。
  代码:
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <cmath>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n;
 9     while(scanf("%d",&n)!=EOF){
10         int sum = 0;
11         for(int i=0;i<=sqrt(n);i++){
12             int j = n-i*i;
13             double t = sqrt(j);
14             if(t-int(t)==0){ //开方成功
15                 if(i!=0 && j!=0)
16                     sum+=4;
17                 else if(i==0 || j==0)
18                     sum+=2;
19             }
20         }
21         printf("%d\n",sum);
22     }
23     return 0;
24 }

 

Freecode : www.cnblogs.com/yym2013

posted @ 2014-03-12 17:21  Freecode#  阅读(334)  评论(0编辑  收藏  举报