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. Android L 使用ART能提高多少性能?

    点击打开链接 刚刚结束的 Google I/O 大会上,Android 下一代操作系统「L」带来不少惊喜.新系统运行更快.更省电. 然而开发者对这个新系统也有颇多疑问,比如新的运行模式 ART 对开发 ...

  2. 抽象工厂在ADO.Net中的应用

    https://msdn.microsoft.com/zh-cn/library/ms971499.aspx http://www.c-sharpcorner.com/UploadFile/moses ...

  3. 爬虫技术(五)-- 模拟简单浏览器(附c#代码)

    由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...

  4. 学习Hadoop的资料

    1)Cygwin相关资料 (1)Cygwin上安装.启动ssh服务失败.ssh localhost失败的解决方案 地址:http://blog.163.com/pwcrab/blog/static/1 ...

  5. 【转】JAVA之网络编程

    转自:火之光 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程的大门而放弃了对于该部分技术的学习. 在 学习网络编程以前,很多初学者 ...

  6. USACO1.4.1 Packing Rectangles

    //毕竟我不是dd牛,USACO的题解也不可能一句话带过的…… 题目链接:http://cerberus.delos.com:790/usacoprob2?a=pWvHFwGsTb2&S=pa ...

  7. MPI编程的常用接口速查

    获取当前时间 在插入MPI提供的头文件后,可以获得获取时间的函数. double MPI_Wtime(void) 取得当前时间, 计时的精度由 double MPI_Wtick(void) 取得作为对 ...

  8. Discuz!NT静态文件缓存(SQUID)

    在目前最新版本的产品中,我们提供了缓存静态文件的解决方案,就是使用SQUID做静态前端,将论坛中的大部分静态文件布署或外链到一个新的HTTP链接上,其中可以外链的静态文件包括:      1.Disc ...

  9. 【Struts】服务器文件的上传和下载

    Java中获得文件的文件后缀 import java.io.*; public class FileTest{ public static void main(String args[]){ File ...

  10. geusture for chrome cfg

    { "name": "Chrome Gestures", "version": "1.13.4", "norm ...