基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
 收藏
 关注
给出一个整数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

如果是之前,估计还在暴力。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long val[31625]; int main()
{
long long i,j=31624,temp,x;
int flag=0;
cin>>x; for(i=0,j=31624;i<=j;)
{
temp=i*i+j*j;
if(temp==x)
{
cout<<i<<" "<<j<<endl;
i++;
j--;
flag=1;
}
else if(temp>x)
{
j--;
}
else if(temp<x)
{
i++;
}
}
if(flag==0)
cout<<"No Solution"<<endl;
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. [LeetCode] Repeated Substring Pattern 重复子字符串模式
  2. Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
  3. 分布式缓存技术memcached学习(五)—— memcached java客户端的使用
  4. Tomcat服务器重启失败:The server may already be running in another process, or a system process may be using the port.
  5. WKWebView _WebFilterIsActive returning: NO
  6. SQL Server 2005 控制用户权限访问表
  7. XML to Entity
  8. 黄聪:MySql Host is blocked because of many connection errors; unblock with &#39;mysqladmin flush-hosts&#39; 解决方法(转)
  9. BZOJ 3511 土地划分
  10. 你所不知道的Html5那些事(一)
  11. 【转】Chrome保存mhtml网页文件的方法 – 无需任何插件,完美!
  12. leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal
  13. Hadoop1.0.4伪分布式安装
  14. block 的演练和使用
  15. CodeForces 591A Wizards&#39; Duel
  16. Part 1:请求与响应--Django从入门到精通系列教程
  17. win10下安装scala
  18. ReentrantLock源码(一)
  19. BZOJ 3751: [NOIP2014]解方程 数学
  20. .NET的堆和栈02,值类型和引用类型参数传递以及内存分配

热门文章

  1. Jmeter测试入门——分析HBase访问服务性能瓶颈
  2. DB2常用sql语句
  3. HTML中用自定义字体实现小图标icon(不是原作, 只是一个研究笔记)
  4. linux网络编程之shutdown() 与 close()函数详解
  5. 基于 若依 ,或者使用 LayUi ,用来展示数据表,同时要 转换字典数据时的转换的建议
  6. SQLmap自动注入工具命令(10.28 10.29 第二十八 二十九天)
  7. TextView标签的属性和跑马灯效果
  8. Java基础(接口,list和ArrayLIst)
  9. C#文本操作
  10. hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )