题目描述

输出不少于100100组不同的本原勾股数: $1≤a≤b≤c≤103$,满足:$a2+b2=c2$且$gcd(a,b,c)=1$

输入

输出

根据描述输出

样例输入

样例输出

3 4 5
5 12 13
....以下省略 你不必输出完全一样,输出不少于100组不同的勾股数,就可以了

题解

#include<iostream>
#include <set>
#include <algorithm>
using namespace std;
struct GG {
    int x, y, z;
    GG(int x, int y, int z) : x(x), y(y), z(z) {
    }
    bool operator<(const GG &g) const {
        if (x != g.x)return x < g.x;
        if (y != g.y)return y < g.y;
        return z < g.z;
    }
};
void solve() {
    set<GG> G;
    for (int i = 1; i <= 20; i++)
        for (int j = i + 1; j <= 40; j++) {
            int x = 2 * i - 1, y = 2 * j - 1;
            if (__gcd(x, y) == 1) {
                int a[3] = {(x * x + y * y) / 2, x * y, (y * y - x * x) / 2};
                sort(a, a + 3);
                if (a[2] > 1000)continue;
                if (G.size() < 100)
                    G.insert(GG(a[0], a[1], a[2]));
            }
        }
    for (GG g: G)cout << g.x << " " << g.y << " " << g.z << endl;
}
int main() {
    solve();
    return 0;
}