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 ...
随机推荐
- [HDOJ1698]Just a Hook(线段树,区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 陈题,更新后查询所有叶节点的和.撸一遍模版,形成自己的风格. #include <algo ...
- java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider
Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvi ...
- 第一次,触碰Web App项目,栽过的那些坑。
此项目是一个IPad上的Web App项目,页面的滚动用了最新的IScroll 5.0 插件, 确实是挺潮的. 项目用时 1个月 完成的, 准备今天晚上上线. 这是年前的最后一篇文章了,与众位博友分享 ...
- UVALive 4128 Steam Roller(最短路(拆点,多状态))
题意:模拟了汽车的行驶过程,边上的权值为全速通过所消耗的时间,而起步(从起点出发的边).刹车(到终点结束的边).减速(即将拐弯的边).加速(刚完成拐弯的边)这四种不能达到全速的情况,消耗的时间为权值* ...
- BZOJ 3573 米特运输
语文题... 原来除了hash还可以取对数啊orz #include<iostream> #include<cstdio> #include<cstring> #i ...
- 基于ffmpeg的流媒体服务器
OS:ubuntu 12.04ffmpeg:N-47141-g4063bb2x264:0.133.2334 a3ac64b目标:使用ffserver建立流媒体服务器使用ffmpeg对本地文件流化(x2 ...
- Android下高斯模糊的算法和demo
采用纯java和RenderScript两种方式来做高斯算法. 也可以用NDK来做,想试试的可以参考: http://stackoverflow.com/questions/2067955/fast- ...
- 一天一个Java基础——序列化
1.概念 Java的“对象序列化”能将一个实现了Serializable接口的对象转换成一组byte,这样日后要用这个对象的时候,能把这些byte数据恢复出来,并据此重新构建那个对象. 对象序列化能实 ...
- Oracle alter index rebuild 与 ORA-08104 说明
在ITPUB 论坛上看到的一个帖子,很不错.根据论坛的帖子重做整理了一下. 原文链接如下: alter index rebuild online引发的血案 http://www.itpub.net/t ...
- Struts2中通配符
1.Struts2中通配符可通过请求的url路径来确定包.类.方法.返回值名. 如 <action name="*_*_*_*" class="cn.javass. ...