蓝桥杯2015 C/C++ A组
方程整数解
【题目描述】
方程: a^2 + b^2 + c^2 = 1000 这个方程有整数解吗?有:a,b,c=6,8,30 就是一组解。
你能算出另一组合适的解吗? 请填写该解中最小的数字。 注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
【题目分析】
枚举,很容易确定一个范围,进行穷举即可
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int max = sqrt(1000); //找一个穷举的范围
for (int a = 1; a <= max; a++)
{
for (int b = a; b <= max; b++)
{
for (int c = b; c <= max; c++)
{
if (a * a + b * b + c * c == 1000)
{
cout << a << " " << b << " " << c << " " << endl;
}
}
}
}
return 0;
}
**结果:**10