HDU 5675 ztr loves math——BestCoder Round #82(div.2)

ztr loves math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as  n=x2y2 .

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
Hint
For the fourth case,105 = 1 32 82
 

Source
BestCoder Round #82 (div.2)
 

/************************************************************************/

附上该题对应的中文题

ztr loves math

 
 
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
ztr喜欢研究数学,一天,他在思考直角三角形方程组的Lower版,即n=x^{2}-y^{2}n=x2y2,他想知道,对于给出的n,是否会有正整数解。
输入描述
有T组数据,第一行为一个正整数T(T<=10^{6})T(T<=106),每一行一个正整数n,n <=10^{18}n<=1018
输出描述
如果有正整数解,输出TrueTrue,否则输出FalseFalse
输入样例
4
6
25
81
105
输出样例
False
True
True
True
Hint
对于第四个样例,有一组解13^{2}-8^{2}=10513282=105
/****************************************************/

出题人的解题思路:

1001.Solution

考虑题目的原型,即给定zz,寻找是否存在一组(x,y)(x,y),满足x^{2}-y^{2}=zx2y2=z

我们可以构造两组等式\begin{bmatrix} (k+1)^{2}-k^{2}=2k+1 \ (k+1)^{2}-(k-1)^{2}=4k \end{bmatrix}[(k+1)2k2=2k+1(k+1)2(k1)2=4k], 很容易得出结论,当z为奇数或者4的倍数时,方程一定有正整数解

此题的注意点在于n=1与n=4的情况,这两种情况算出来的y均为0,但题目明确指出是正整数解

故而x+y与x-y必定同奇同偶

①当x+y与x-y同为奇数时,不妨构造x-y=1

那么只需n≠1且n为奇数,那么方程组必定有解;

②当x+y与x-y同为偶数时,不妨构造x-y=2

那么只需n≠4且n为4的倍数,那么方程组必定有解

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 100005;
const int M = 40;
const int inf = 100000000;
const int mod = 2009;
int main()
{
    int t;
    __int64 n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        if(n%2&&n!=1)
            puts("True");
           else if(n!=4&&n%4==0)
               puts("True");
        else
            puts("False");
    }
    return 0;
}
菜鸟成长记

你可能感兴趣的:(Math,ACM)