HDU 5675 ztr loves math (数学推导)
ztr loves math
题目链接:
http://acm.hust.edu.cn/vjudge/contest/123316#problem/A
Description
ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as n = x^2 - y^2.
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 indicating the number of test cases.
For each test case:each line contains a positive integer ,.
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 = 132-82.
题意:
给出一个N(N<=10^18);
问N能否由两个完全平方数相减得到;
题解:
对于相邻自然数 n 和 n+1 :
(n+1)^2 - n^2 = 2n+1;
即相邻两平方数之差一定是一个奇数;
那么任意两个平方数之差一定是多个连续奇数的和.
而任意两个连续奇数之和为:
(2n-1) + (2n+1) = 4n;
即两个连续奇数之和必定能整除4;
那么本题满足条件的n须两个性质之一:
- N为奇数
- N能被4整除;
特判:由于题目要求任一平方数不能为0;
则1和4不满足要求.
TLE了一发:把puts和cin都换掉就过了...
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 1100
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
LL n;
int main(int argc, char const *argv[])
{
//IN;
int t; scanf("%d", &t);
while(t--)
{
scanf("%I64d", &n);
if(n == 1 || n==4) {
printf("False\n");
continue;
}
if(n&1 || n%4==0) printf("True\n");
else printf("False\n");
}
return 0;
}
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)To ...
- hdu 5675 ztr loves math(数学技巧)
Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...
- hdu-5675 ztr loves math(数学)
题目链接: ztr loves math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5677 ztr loves substring(Manacher+dp+二进制分解)
题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...
- HDU 5677 ztr loves substring(回文串加多重背包)
ztr loves substring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5676 ztr loves lucky numbers (模拟)
ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...
- hdu 5676 ztr loves lucky numbers(dfs+离线)
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...
- hdu 5676 ztr loves lucky numbers 打表+二分
ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
随机推荐
- Myeclipse多行注释快捷键及其他快捷键
当时我看到struts2讲解视频的时候,讲解员居然能一下子注释掉好几行代码,而且注释的很整齐,然我大吃一惊,上网搜了下Myeclipse的快捷键还真多 选择你要注释的那一行或多行代码,按Ctrl+/即 ...
- HDU 3949 XOR(高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题意:给出一个长度为n的数列A.选出A的所有子集(除空集外)进行抑或得到2^n-1个数字,去重排 ...
- Oracle学习之集合运算
一.集合运算操作符 UNION:(并集)返回两个集合去掉重复值的所有的记录 UNION ALL:(并集)返回两个集合去掉重复值的所有的记录 INTERSECT:(交集)返回两个集合的所有记录,重复 ...
- ArrayList和List之间的转换
开发中不免碰到List与数组类型之间的相互转换,举一个简单的例子: package test.test1; import java.util.ArrayList; import java.util.L ...
- Hadoop configration类分析
configration这个类是分析hadoop源代码一个很好地入口. 先从需求说起.对于一个大型的文件系统,基于配置文件可以增强灵活性.congfigration类就是为了管理配置文件的. 配置文件 ...
- <五>面向对象分析之UML核心元素之边界
一:基本概念
- 【转】pdf 中如何把几页缩小成一页打印
我用的是Foxit PDF Reader,可以这样设置:文件-打印-打印处理下的页面排列选择“在每张纸上放置多页”-选择每页版数即可. 如果你用的是Adobe Reader,也可以自己找一下,看是否有 ...
- MySQL基础之第2章 Windows平台下安装与配置MySQL
2.1.msi安装包 2.1.1.安装 特别要注意的是,安装前要删除原来的my.ini和原来的data目录,改名也行,不然在最后一步会“apply security settings”报个1045错误 ...
- T-SQL查询进阶-10分钟理解游标
转:http://www.cnblogs.com/CareySon/archive/2011/11/01/2231381.html 概述 游标是邪恶的! 在关系数据库中,我们对于查询的思考是面向集合的 ...
- spring aop expression简单说明
<aop:config> <aop:pointcut id="userDAO" expression="execution(public * cn.da ...