您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: