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须两个性质之一:

  1. N为奇数
  2. 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 (数学推导)的更多相关文章

  1. HDU 5675 ztr loves math

    ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. hdu 5675 ztr loves math(数学技巧)

    Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...

  3. hdu-5675 ztr loves math(数学)

    题目链接: ztr loves math  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Othe ...

  4. HDU 5677 ztr loves substring(Manacher+dp+二进制分解)

    题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...

  5. HDU 5677 ztr loves substring(回文串加多重背包)

    ztr loves substring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  6. HDU 5676 ztr loves lucky numbers (模拟)

    ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...

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

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  8. hdu 5676 ztr loves lucky numbers 打表+二分

    ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  9. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

随机推荐

  1. 20-语言入门-20-Financial Management

    题目地址: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=72    描述Larry graduated this year and fina ...

  2. EBS报表输出文件格式控制

    具体使用方法:1.添加用户参数p_conc_request_id2.在BeforeReport trigger中添加srw.user_exit('FND SRWINIT');          和Af ...

  3. Web内容管理系统 Magnolia 安装使用-挖掘优良的架构(2)

    在Windows上安装社区版  tomcat集成版 Magnolia CMS社区版本为免费发行,不需要任何GNU通用公共许可协议(第3版)条款下的授权(这个许可协议允许您在特定条款和条件下,重新分配和 ...

  4. JdbcTemplate查询数据 三种callback之间的区别

    JdbcTemplate针对数据查询提供了多个重载的模板方法,你可以根据需要选用不同的模板方法. 如果你的查询很简单,仅仅是传入相应SQL或者相关参数,然后取得一个单一的结果,那么你可以选择如下一组便 ...

  5. 基于ffmpeg的简单音视频编解码的例子

    近日需要做一个视频转码服务器,对我这样一个在该领域的新手来说却是够我折腾一番,在别人的建议下开始研究开源ffmpeg项目,下面是在代码中看到的一 段例子代码,对我的学习非常有帮助.该例子代码包含音频的 ...

  6. JOB的创建,定时,执行

    --建表 create table test_job(para_date date);  commit;  insert into test_job values(sysdate);  commit; ...

  7. Android 如何直播RTMP流

    在android上,视频/音频流直播是极少有人关注的一部分.每当我们讨论流媒体,RTMP(Real Time Messaging Protocol)是不可或缺的.RTMP是一个基本的视频/音频直播流协 ...

  8. MySQL基础之第5章 操作数据库

    假设已经登录 mysql-h localhost -uroot -proot 5.1.显示.创建.删除数据库 show databases;     显示所有的数据库 create database ...

  9. Android-AnimationDrawable(二)

    首先可以先定义一个逐帧播放的xml: <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  10. 在英文 sql2005中 比较nvarchar 与 varchar的速度

    declare @str1 varchar(max); declare @count int; ; print 'begin' begin set @str1 = @str1 + '*'; ; end ...