solution.cpp 751 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n;
    bool flag = false;
    while (cin >> n)
    {
        flag = false;
        for (int i = 1; i <= sqrt(n); i++)
        {
            for (int j = i; j <= sqrt(n); j++)
            {
                for (int k = j; k <= sqrt(n); k++)
                {
                    if (i * i + j * j + k * k == n)
                    {
                        cout << i << ' ' << j << ' ' << k << endl;
                        flag = true;
                    }
                    else if (i * i + j * j + k * k > n)
                        break;
                }
            }
        }
        if (!flag)
            cout << "No Solution" << endl;
    }

    return 0;
}