HDU 5675 ztr loves math——BestCoder Round #82(div.2)
2016-04-30 21:59
555 查看
ztr loves math
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as n=x2−y2.
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 T(T<=106) indicating
the number of test cases.
For each test case:each line contains a positive integer ,n<=1018.
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
HintFor the fourth case,105 = 132−82
Source
BestCoder Round #82 (div.2)
/************************************************************************/
附上该题对应的中文题
ztr loves math
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
ztr喜欢研究数学,一天,他在思考直角三角形方程组的Lower版,即n=x^{2}-y^{2}n=x2−y2,他想知道,对于给出的n,是否会有正整数解。
输入描述
有T组数据,第一行为一个正整数T(T<=10^{6})T(T<=106),每一行一个正整数n,n <=10^{18}n<=1018
输出描述
如果有正整数解,输出TrueTrue,否则输出FalseFalse
输入样例
4 6 25 81 105
输出样例
False True True True
Hint
对于第四个样例,有一组解13^{2}-8^{2}=105132−82=105
/****************************************************/
出题人的解题思路:
1001.Solution
考虑题目的原型,即给定zz,寻找是否存在一组(x,y)(x,y),满足x^{2}-y^{2}=zx2−y2=z我们可以构造两组等式\begin{bmatrix}
(k+1)^{2}-k^{2}=2k+1 \ (k+1)^{2}-(k-1)^{2}=4k \end{bmatrix}[(k+1)2−k2=2k+1(k+1)2−(k−1)2=4k],
很容易得出结论,当z为奇数或者4的倍数时,方程一定有正整数解
此题的注意点在于n=1与n=4的情况,这两种情况算出来的y均为0,但题目明确指出是正整数解
故而x+y与x-y必定同奇同偶
①当x+y与x-y同为奇数时,不妨构造x-y=1
那么只需n≠1且n为奇数,那么方程组必定有解;
②当x+y与x-y同为偶数时,不妨构造x-y=2
那么只需n≠4且n为4的倍数,那么方程组必定有解
/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 100005;
const int M = 40;
const int inf = 100000000;
const int mod = 2009;
int main()
{
int t;
__int64 n;
scanf("%d",&t);
while(t--)
{
scanf("%I64d",&n);
if(n%2&&n!=1)
puts("True");
else if(n!=4&&n%4==0)
puts("True");
else
puts("False");
}
return 0;
}菜鸟成长记
相关文章推荐
- hdu2211 杀人游戏(约瑟夫环)
- 第91课:SparkStreaming基于Kafka Direct案例实战和内幕源码解密 java.lang.ClassNotFoundException 踩坑解决问题详细内幕版本
- C/C++,C#,JAVA数组
- AC自动机详解
- 文件服务器NFS
- python猜数字小游戏
- C++模板详解
- OK6410 uboot编译以及设置uboot开机自动启动内核
- Java多线程通信方式
- 【Linux】-----简单易学的安装
- ubuntu or debian下安装php mysql apache phpmyadmin
- 初识AngularJS
- 源码阅读笔记 - 3 std::string 与 Short String Optimization
- ATL-style templates
- map的基础知识
- Qt学习笔记之文本编辑器实现加粗、倾斜、下划线、字体、居中对齐、左对齐、右对齐
- 课程设计__对象指针
- 第九周学习进度
- python&&CMD
- script标签位置的放置