hdoj-5675-ztr loves math

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

把前面几个数的平方数拿出来
1 4 9 16 25 36 49 64…
分一个做差为
3 5 7 9…
分两个做差为
8 12 16….
依次类推会发现只会和4的倍数(除了4)奇数(除了1)有关

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        if((n%4==0&&n!=4)||(n%2==1&&n!=1))
            printf("True\n");
        else printf("False\n");
    }
    return 0;
}

你可能感兴趣的:(hdoj-5675-ztr loves math)