ACM刷题之HDU————ztr loves math

本文探讨了一种数学问题的解决方法,该问题涉及判断给定正整数n是否可以表示为两个正整数平方差的形式。通过观察和分析一系列数值规律,文章提出了一种简单有效的解决方案,并给出了相应的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ztr loves math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 165    Accepted Submission(s): 75


Problem Description
ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as n=x2y2.

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
Hint
For the fourth case,$105 = 13^{2}-8^{2}$
 


这题有点找规律的感觉。。

先列出前几项的平方,试着找下规律

1 4 9 16 25 36 49 64 81

这几项是1-9的平方。我试着相邻的数减下?嗯 得到

3 5 7 9 11 13 15 17

我的天呐,是不是感觉发现了什么?没错。就是奇数啊(1要特判!注意)


那再试试隔一项减下 得到

8 12 16 20 24 28 32

是不是又发现了? 嗯 都是4的倍数诶!(4要特判)


再隔两项? 得到

15 21 33...

规律是? 虽然不是很明白,但是肯定是奇数!


下面再隔三项也是一样,还是会得到4的倍数


所以我们可以猜测下 满足题目条件的数应该是满足是奇数或者是4的倍数(1和4要特判!!!)

所以我们不难写出下面的ac代码


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	__int64 n,a,b,i,j,num;
	scanf("%I64d",&n);
	while(n--)
	{
		scanf("%I64d",&num);
		if((num%2==1&&num!=1)||(num%4==0&&num!=4))
		printf("True\n");
		else
		printf("False\n");		
	}	
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值