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 ...
随机推荐
- class_create()
#define class_create(owner, name) \({ \ ...
- Android软件开发需要学什么
首先,需要学习哪些Android开发技术? Android的开发技术很多,在开始学习的时候不可能一次性全部学会,也没有必要一开始都全部学会,但是有些技术是非常常用的,需要在开始时打好基础,这些技术时: ...
- bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式
后缀数组+二分答案+离散化.(上次写的时候看数据小没离散化然后一直WA...写了lsj师兄的写法. #include<cstdio> #include<cstring> #in ...
- ZJ2008树的统计(树链剖分)
type node1=record go,next:longint;end; node2=record l,r,mx,sum:longint;end; var i,x,y,n,q,tmp,cnt,sz ...
- IIS修改队列长度(IIS6+IIS7)
Internet Information Services (IIS) 限制了在任何给定时间可在队列中等待的应用程序池请求的最大数量.如果达到此限制,则所有新请求都将被拒绝,而且用户将收到错误消息“5 ...
- 发布到IIS的时候用户 'WWW-6743CC520E9\ASPNET' 登录失败
在 webConfig 数据连接那里 别用集成验证方式 使用用户名密码的方式连接
- 页面多个Jquery版本共存的冲突问题,解决方法!
示例如下: <script type="text/javascript" src="jquery.js"></script> <s ...
- ffmpeg Windows下采集摄像头一帧数据,并保存为bmp图片
这里请注意,在编译ffmpeg时,不要使用--disable-devices选项. 使用 --enable-encoder=rawvideo --enable-decoder=rawvideo 启用r ...
- svn强制提交备注信息
当我们用tortoisesvn,提交代码时,有很多人不喜欢写注释的,代码版本多了,根本搞不清,哪个版本改了什么东西?所以如果加一些注释的话,我们看起来,也方便很多.所以在提交的时候,我会强制要求,写注 ...
- 【转】android 自定义控件 使用declare-styleable进行配置属性(源码角度)
原文网址:http://blog.csdn.net/vipzjyno1/article/details/23696537 最近在模仿今日头条,发现它的很多属性都是通过自定义控件并设定相关的配置属性进行 ...