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 ...
随机推荐
- Bundle使用&NSBundle
之 前在初始化一个类的时候:TestViewController *viewcontroller=[[TestViewController alloc]initWithNibName:@"T ...
- 【编程技巧】ExtJs 设置GridPanel表格文本垂直居中
详细讲解见 http://blog.csdn.net/li396864285/article/details/9310983 以下是我改修的代码: { width:90, ...
- Google免费GPU使用教程
今天突然看到一篇推文,里面讲解了如何薅资本主义羊毛,即如何免费使用Google免费提供的GPU使用权. 可以免费使用的方式就是通过Google Colab,全名Colaboratory.我们可以用它来 ...
- 如何开发由Create-React-App 引导的应用(四)
此文章是翻译How to develop apps bootstrapped with Create React App 官方文档 系列文章 如何开发由Create-React-App 引导的应用 如 ...
- Mysql执行计划说明
Mysql执行计划翻译: 官网原文请见http://dev.mysql.com/doc/refman/5.6/en/explain-output.html:5.6 EXPLAIN语句提供有关SELEC ...
- 安卓开发-intent在Activity之间数据传递
安卓开发-intent在Activity之间数据传递 [TOC] intent实现普通跳转 使用intent的setclass方法,示例(由此界面跳转到NewActivity界面) //使用setOn ...
- -bash: warning: setlocale: LC_CTYPE: cannot change locale (EN_US.UTF-8): No such file or directory
出问题原因: 通过 su - 切换用户时候,LANG设置为en或者设置错误,切换角色会出现这个错误 如何解决? echo $LANG # 查看 LANG 参数 sed 's#LANG=en#LANG= ...
- linux 中 ping的回传值
今天在学习鸟哥私房菜的过程中,不明白ping的回传值是怎么设置的,后来网上找的结果了,特此记录一下 1 题目大意是指,ping一个网段的机器,如果可以通,就显示UP,如果不通就显示Down,其中一 ...
- 在Tomcat中配置单点登录
单点登录:Single Sign-On .概述 一旦你设置了realm和验证的方法,你就需要进行实际的用户登录处理.一般说来,对用户而言登录系统是一件很麻烦的事情,你必须尽量减少用户登录验证的次数.作 ...
- php curl模拟登陆抓取数据
http://www.cnblogs.com/zengguowang/p/6814474.html