hdu--3835--最简单的数学..

这应该是最简单的数学了吧...

给你一个数N 问有多少种方法可以组成N=A^2+B^2..

对于样例1 R(2)=4 分别是 <1,-1>   <1,1>   <-1,1>  <-1,-1>其他的情况 题目hint已经告诉我们了

这题 直接上代码吧=-=

 1 #include <iostream>
 2 #include <cmath>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     double n , a , b;
 8     int ans;
 9     while( cin >> n )
10     {
11         ans = 0;
12         if( !n )
13             cout << 1 << endl;
14         else
15         {
16             for( int i = 0 ; i*i<=n/2 ; i++ )
17             {
18                 a = sqrt( (n-i*i)*1.0 );
19                 b = floor(a);
20                 if( a==b )
21                 {
22                     if( !i )
23                         ans +=4;
24                     else if( i*i*2==n )
25                         ans +=4;
26                     else
27                         ans +=8;
28                 }
29             }
30             cout << ans << endl;
31         }
32     }
33     return 0;
34 }
View Code

好像 这套 multi-university-contest蛮适合我现在的饿..

just follow your heart
原文地址:https://www.cnblogs.com/radical/p/3931865.html