Problem Description
K likes to play with the balls.That day he piled a triangle (n layers, layer 1 start,the first layer has 1 ball,the secode layer has 2 balls,……,the nth layer has n balls), but he felt uncomfortable after completion, and want to pile a right triangle, because he felt that the number 4 is a lucky one (because of “si ji fa cai”). So he decided to use 4 times of the balls he just used as a right-edge side of the right triangle(the three edges have no common factor).He only to pile the three edges,that is the middle is empty.But there will not have so many balls,so he wants to know the minimum of balls he must use.Now ,he turn to you for help.
Input
The layer of the triangle as the promble describes n,1 <= n < 2^16
Output
The minimum of balls he must use and the length of the hypotenuse. One case one line
Sample Input
1 2 3
Sample Output
9 5 27 13 53 25 The second case: Let the right_edge promble describles is b ,The layer is 2,so b is 4 * (1 + 2) = 12.wo can know the edges of right triangle is 5 , 12 ,13. So the minimum of balls he must use is (5 + 12 + 13 – 3) = 27
Author
Klion@CSU
Source
Recommend
lcy
题意很简单,给定n,求4*(1+..+n)为直角三角形一直角边长的三角形中,周长最小的三角形的斜边和(周长-3),且三边长为整数且三边长无公因子。 ps:因为题目中说是摆小球,所以周长会吧三个顶点都算了两遍。
首先4*(1+...+n)=2n^2+2n,在前面提到过了,如果一个直角三角形三边长为整数且无公因子,则三个数为本原勾股数组,其通项为(st,(s^2-t^2)/2,(s^2+t^2)/2),所以推导过程如下:

这样代码就一行解决了,话说前几天宣儿还说我做的题一般推半天结果最后随便敲两行代码过的……看来是真的咩……orz
代码象征性的送上,另外终于搞清楚hdu的longlong要用%I64d,不然会错的……
#include <stdio.h>
int main()
{
long long i,j,n;
while(scanf("%I64d",&n)!=EOF)
{
printf("%I64d %I64d\n",4*n*n+6*n-1,2*n*n+2*n+1);
}
return 0;
}
本文探讨了一个特定的排列组合问题,即构造一个直角三角形,使得使用的小球数量最少,并且该三角形的一条边长是4倍的连续自然数之和。文章详细介绍了问题的数学背景、求解思路以及最终的代码实现,通过实例演示了如何通过数学推导和编程技巧解决实际问题。
1499

被折叠的 条评论
为什么被折叠?



