HDU5675
2016-05-10 21:02
246 查看
ztr loves math
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 766 Accepted Submission(s): 296
Problem Description
ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as n=x2−y2.
He wanted to know that ,for a given number n,is there a positive integer solutions?
Input
There are T test cases.
The first line of input contains an positive integer T(T<=106) indicating
the number of test cases.
For each test case:each line contains a positive integer ,n<=1018.
Output
If there be a positive integer solutions,print True,else
print False
Sample Input
4 6 25 81 105
Sample Output
False True True True HintFor the fourth case,$105 = 13^{2}-8^{2}$
Source
BestCoder Round #82 (div.2)
Recommend
wange2014 | We have carefully selected several similar problems for you: 5679 5678 5677 5676 5674
//思路:
//n=x^2-y^2=(x+y)*(x-y),令a=(x+y),b=(x-y),解得x=(a+b)/2,y=(a-b)/2;因为x和y都是整数,所以a与b同奇数同偶数
//当a与b都是奇数时,n=a*b 必定是奇数,但a!=b,所以n不为1;
//但a与b都是偶数时,n=a*b必定是4的倍数,但a!=b,所以n不为4;
//综上,当n是奇数或4的倍数且不是1和4时n=x^2-y^2有解
#include <iostream> #include <cstdio> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { long long n; scanf("%I64d",&n); if(n == 1 || n == 4) { printf("False\n"); continue; } else if(n % 2 == 1 || n % 4 == 0) { printf("True\n"); continue; } else printf("False\n"); } return 0; }
相关文章推荐
- C语言 调整一个数组的顺序,使得奇数在总在偶数的前边
- 排序
- 多线程01:《疯狂Java讲义》学习笔记——线程概述
- python 推导式
- SQL中数据库的基本操作
- 昆明各区县设点办理残疾人公交和地铁爱心卡
- 专题三 · 1015
- 桶排序——一步一步算法篇
- JAVA基础之——注解的生命周期
- 7zip压缩及排除目录或文件
- poj 3253 优先队列
- 局部敏感哈希Locality Sensitive Hashing(LSH)之随机投影法
- fedora 23 google-chrome 以root打开(转载)
- ny 228 士兵杀敌(五)-- 神题,慢慢理解(线段树 区间更新,区间求和)
- Java中static的使用
- 典型描述
- Unity打包Android备忘
- Css基本样式————文本
- AutoStitch一种新的高维图像自动拼接方法AutoStitch: a new dimension in automatic image stitching
- 如何在Mac OS X上安装 Ruby运行环境