ACM模版

描述

题解

注意查找的范围即可(设置一个标志范围的哨兵),一道水题,无需多言。

代码

#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[])
{
    int N;
    while (cin >> N)
    {
        int A;
        double B;
        double flag = N;
        bool tag = true;
        if (N == 1)
        {
            cout << "0 1\n";
            tag = false;
        }
        for (A = 1; A < flag; A++)
        {
            B = sqrt(N - A * A);
            flag = B;
            if (B == (int)B)
            {
                cout << A << ' ' << B << '\n';
                tag = false;
            }
        }
        if (tag)
        {
            cout << "No Solution\n";
        }
    }

    return 0;
}