B题 hdu 1407 测试你是否和LTC水平一样高

时间:2025-05-06 16:07:08

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1407

测试你是否和LTC水平一样高

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14769    Accepted Submission(s): 4843

Problem Description
大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上! 你的任务是: 计算方程x^2+y^2+z^2= num的一个正整数解。
Input
输入数据包含多个测试实例,每个实例占一行,仅仅包含一个小于等于10000的正整数num。
Output
对于每组测试数据,请按照x,y,z递增的顺序输出它的一个最小正整数解,每个实例的输出占一行,题目保证所有测试数据都有解。
Sample Input
3
Sample Output
1 1 1
Author
lcy
Source
题目大意:找到符合计算方程x^2+y^2+z^2= num的x,y,z。
特别注意:1、x,y,z按照递增的顺序输出。
       2、找不到符合的x,y,z就不输出。
       3、注意输出的是正整数,0不包含在内。
详见代码。
 #include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; int n; void fun()
{
for (int i=; i<=; i++)
{
for (int j=i; j<=; j++)
{
for (int k=j; k<=; k++)
{
if (i*i+j*j+k*k==n)
{
printf ("%d %d %d\n",i,j,k);
return ;
}
} }
}
} int main ()
{
while (~scanf("%d",&n))
{
fun();
}
return ;
}