hdu 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

Hint

For the fourth case,$105 = 13^{2}-8^{2}$

给定nz,寻找是否存在一组(x,y),满足x^2-y^2=n,那么我们可以构造两个方程 即(k+1)^2-k^2=n和(k+1)^2-(k-1)^2=n,得出结论,当n为奇数或者4的倍数时,方程一定有正整数解,但要记得特判1和4

AC代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 #define ll long long
 6 ll n;
 7 int main()
 8 {
 9     int t;
10     scanf("%d",&t);
11     while(t--){
12        scanf("%I64d",&n);
13        if(n==1 || n==4){
14           printf("False\n");
15           continue;
16        }
17        if(n%2==1 || n%4==0){
18            printf("True\n");
19        }else{
20            printf("False\n");
21        }
22     }
23     return 0;
24 }
时间: 2024-11-05 19:28:48

hdu 5675 ztr loves math(数学技巧)的相关文章

HDU 5675 ztr loves math

ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 896    Accepted Submission(s): 347 Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" of

hdu-5675 ztr loves math(数学)

题目链接: 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=x?2??−y?2??,他想知道,对于给出的n,是否会有正整数解. 输入描述 有T组数据,第一行为一个正整数T(T<=10^{6})T(T<=10?6??),每一行一个正整数n,n &l

hdu 5677 ztr loves substring 二维费用背包+回文

题目链接: hdu 5677 ztr loves substring 官方题解: //这部分是错的(首先,对于每一个串i跑一次manancher,令g[i][j]=p[j]-1g[i][j]=p[j]−1 这样,g就存储了所有的回文子串的长度 为了方便,把g降到一维表示) 首先,因为字符串长度较小,所以直接二重for循环找就好了,用一个数组 g记录各个回文串的长度 不妨把每一个子串抽象成一个物品 费用为二维的,即{长度,1} 价值是Bool型的 这样就成了一个二维判断可行性费用背包问题 设f(i

hdu 5676 ztr loves lucky numbers(BC——暴力打表+二分查找)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 594    Accepted Submission(s): 257 Problem Description ztr loves luck

hdu 5676 ztr loves lucky numbers(dfs+离线)

Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is

hdu 5676 ztr loves lucky numbers

题目链接:hdu 5676 一开始看题还以为和数位dp相关的,后来才发现是搜索题,我手算了下,所有的super lucky number(也就是只含数字4, 7且4, 7的数量相等的数)加起来也不过几万个,可以采用打表的方法来把所有的super lucky number存储起来.因为4,7数量须相等,所以可以用一个二进制数的0,1来代替,先限定4,7数量分别为 i,之后就是求出包含 i 个0和 i 个1的 2*i 位所有这样的二进制数,然后简单转换一下(1->7, 0->4,这样子能从小到大

hdu 5677 ztr loves substring(manacher,背包问题)

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 /** 6 7 8 manacher 处理出回文串长度 9 p[i]:半径 10 11 if(s[i] == '#' && p[i] == 1) continue; 12 else{ 13 int tmp = p[i] / 2; 14 if(s[i] == '#') for(int i = 2 ; i <= tmp ;

HDU 5678 ztr loves trees

这题也是一眼标算..... 先搞一次dfs,把树转换成序列,对每个节点看子树的中位数,也就是看某段区间的中位数,这样就可以主席树求区间第k大值解决. 注意:询问的次数有1000000次,每次去询问会TLE的.注意到询问的种类只有100000种,所以之前询问过的可以0(1)得到,或者直接处理出每一种询问的答案. 还有一个问题:小数取模...用fmod函数. #include<cstdio> #include<cstring> #include<cmath> #includ

HDU 5677 ztr loves substring

Manacher+二维费用多重背包 二进制优化 这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解. 多重背包做的时候需要二进制优化. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn = 300; int N, p[maxn]; char str[maxn