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

时间:2014-08-23 22:52:51   收藏:0   阅读:227

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

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

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

这题 直接上代码吧=-=

bubuko.com,布布扣
 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蛮适合我现在的饿..

 

原文:http://www.cnblogs.com/radical/p/3931865.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!