码迷,mamicode.com
首页 > 其他好文 > 详细

51Nod 1080 两个数的平方和

时间:2017-07-29 18:52:47      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:math   return   code   inpu   ==   mod   tput   inf   cti   

给出一个整数N,将N表示为2个整数i j的平方和(i <= j),如果有多种表示,按照i的递增序输出。
 
例如:N = 130,130 = 3^2 + 11^2 = 7^2 + 9^2 (注:3 11同11 3算1种)
Input
一个数N(1 <= N <= 10^9)
Output
共K行:每行2个数,i j,表示N = i^2 + j^2(0 <= i <= j)。
如果无法分解为2个数的平方和,则输出No Solution
Input示例
130
Output示例
3 11
7 9
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 using namespace std;
13 #define lowbit(x) (x&(-x))
14 #define max(x,y) (x>y?x:y)
15 #define min(x,y) (x<y?x:y)
16 #define MAX 100000000000000000
17 #define MOD 1000000007
18 #define pi acos(-1.0)
19 #define ei exp(1)
20 #define PI 3.141592653589793238462
21 #define INF 0x3f3f3f3f3f
22 #define mem(a) (memset(a,0,sizeof(a)))
23 typedef long long ll;
24 const int N=10005;
25 const int mod=1e9+7;
26 
27 int main()
28 {
29     int n;
30     cin>>n;
31     int m=(int)sqrt(n)+0.5;
32     int i,j=1;
33     int flag=1;
34     for(i=m;i>=1;i--){
35         for(j=0;j<=i;j++){
36             if(i*i+j*j==n){
37                 flag=0;
38                 cout<<j<<" "<<i<<endl;
39             }
40         }
41     }
42     if(flag) cout<<"No Solution"<<endl;
43     return 0;
44 }

 

51Nod 1080 两个数的平方和

标签:math   return   code   inpu   ==   mod   tput   inf   cti   

原文地址:http://www.cnblogs.com/shixinzei/p/7257075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!