hdu4143 A Simple Problem
A Simple Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 5748 Accepted Submission(s): 1515
Then T line followed each containing an integer n (1<=n <= 10^9).
2
3
1
// y^2 = n +x^2.即 (y+x)(y-x) = n
//设 i = y-x, n/i = y+x , x = (n/k-k)%2 由于 x, y是正整数, 则 y,x不会等于0, 所以这边还有一点最重要的(y+x) (y-x) 不能相等
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int t, n, i, flag, x;
cin >> t;
while(t--)
{
cin >> n;
flag = 0;
i = sqrt(n);
for(int k = i; k >=1; k--) //题意是求符合条件,最小的x, 所以 k 要从最大因子开始判断
{
if(n%k == 0 && (n/k-k)%2 == 0 && n/k != k) //控制好符合条件是最重要的
{
x = (n/k - k)/2;
cout << x << endl;
flag = 1;
break;
}
}
if(flag == 0)
{
cout << -1 << endl;
}
}
return 0;
}
hdu4143 A Simple Problem的更多相关文章
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92632 ...
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
随机推荐
- MySQL改写子查询成Join
有时用别的方式而不是子查询可以获得更高的性能 : For example: SELECT * FROM t1 WHERE id IN (SELECT id FROM t2); 改写: SELECT D ...
- 详解javascript中的闭包
全局变量与局部变量 在说闭包之前先说明全局变量与局部变量 全局变量:变量声明时如果不使用 var 关键字,那么它就是一个全局变量,即便它在函数内定义. 局部变量:使用var关键字定义 全局变量/局部变 ...
- String 类的选择输出
package com.day_08.strings; /* * 通过API可知/String是在Java.lang包下的类,所以不用导包 */ public class StringDemo { p ...
- jdk源码->集合->LinkedList
类的属性 public class LinkedList<E> extends AbstractSequentialList<E> implements List<E&g ...
- HTML5入门要点
要点 HTML5是HTML的最新版本.通过引入心的标签.新的语义和媒体元素,同时要依赖一组支持Web应用的JavaScript库 XHTML不再是Web页面开发标准.开发人员和W3C组织觉决定还是继续 ...
- sed,n,N,d,D,p,P,h,H,g,G,x,解析
原文地址 这篇文章主要是我参考命令的,直接复制粘贴,有问题请拍砖 A. sed执行模板=sed '模式{命令1;命令2}' 即逐行读入模式空间,执行命令,最后输出打印出来 B. p打印当前模式空间所有 ...
- Nagios在selinux开启的情况下使用
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/ # chcon -R -t httpd_sys_content_t /usr/loc ...
- 浅谈ES6
ECMAScript6.0(简称ES6)是javaScript语言的下一代标准,已经在2015年6月正式发布了.它的目标,使得javaScript语言可以用来编写复杂的大型应用程序,成为企业级开发语言 ...
- 记React+.NetCore API实现动态列导出
1.效果演示 2.用到的第三方类库 前端:React,Dva,Antd 后端:ASP.NET CORE,System.Linq.Dynamic.Core,EPPlus.Core 3.基本思路 第一:E ...
- docker命令行学习
docker命令行学习 docker run docker run --help:老实说这条最管用了 docker run -it:交互模式,允许控制台输出 docker run -d:detach, ...