ztr loves math
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 165 Accepted Submission(s): 75
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?
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.
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 TrueHintFor the fourth case,$105 = 13^{2}-8^{2}$
这题有点找规律的感觉。。
先列出前几项的平方,试着找下规律
1 4 9 16 25 36 49 64 81
这几项是1-9的平方。我试着相邻的数减下?嗯 得到
3 5 7 9 11 13 15 17
我的天呐,是不是感觉发现了什么?没错。就是奇数啊(1要特判!注意)
那再试试隔一项减下 得到
8 12 16 20 24 28 32
是不是又发现了? 嗯 都是4的倍数诶!(4要特判)
再隔两项? 得到
15 21 33...
规律是? 虽然不是很明白,但是肯定是奇数!
下面再隔三项也是一样,还是会得到4的倍数
所以我们可以猜测下 满足题目条件的数应该是满足是奇数或者是4的倍数(1和4要特判!!!)
所以我们不难写出下面的ac代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
__int64 n,a,b,i,j,num;
scanf("%I64d",&n);
while(n--)
{
scanf("%I64d",&num);
if((num%2==1&&num!=1)||(num%4==0&&num!=4))
printf("True\n");
else
printf("False\n");
}
}