微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Heron and His Triangle HDU - 6222pell 大数

---恢复内容开始---

heron and His Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2543    Accepted Submission(s): 1060


Problem Description
A triangle is a heron’s triangle if it satisfies that the side lengths of it are consecutive integers t−1,t,t+ 1 and thatits area is an integer. Now,for given n you need to find a heron’s triangle associated with the smallest t bigger
than or equal to n.
 

 

Input
The input contains multiple test cases. The first line of a multiple input is an integer T (1 ≤ T ≤ 30000) followedby T lines. Each line contains an integer N (1 ≤ N ≤ 10^30).
 

 

Output
For each test case,output the smallest t in a line. If the heron’s triangle required does not exist,output -1.
 

 

Sample Input
4 1 2 3 4
 

 

Sample Output
4 4 4 4
 

 

Source
 

 

Recommend
jiangzijing2015

 

遇到求三角形面积且已知三边长 那就用海伦公式

分享图片

 

 

 

heron and His Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2543    Accepted Submission(s): 1060


Problem Description
A triangle is a heron’s triangle if it satisfies that the side lengths of it are consecutive integers t−1,monospace'> 4 4 4 4
 

 

Source
 

 

Recommend
jiangzijing2015

首先根据题意设a=t-1,b=t,c=t+1,这样我们可由海伦凯勒公式得到

                           

那么要想使得s为整数,就要使      等于3乘以一个平方数

所以我们设            

于是得到               d=3

根据题意可知最小特解为x=2,y=1;

分享图片

打个表之后发现这样一些数字4,14,52,194,724,2702....然后得出递推式子,F[n]=4*F[n-1]-F[n-2];由于n非常的大,所以矩阵快幂维护也不行。最后考虑这样的数字几乎增长比较快,那么范围内这样的数字就会比较少,不想用高精度的可以考虑用java大数了,用个list将所有n范围内的结果保存一下,最后直接查询就可以了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐