#include #define N 100 long max(long a, long b) { return a > b ? a : b; } bool even(long i) { return i % 2 == 0; } long gcd(long a, long b) { while (b != 0) { long c = a % b; a = b; b = c; } return a; } long factors[N]; int nr_factors; void analyse(long ai, long bi, long aj, long bj, long n) { printf(" %2ld %2ld %2ld %2ld ", ai, bi, aj, bj); long c = (ai + aj)/2; long d = (aj - ai)/2; long e = (bi + bj)/2; long f = (bi - bj)/2; printf(" %3ld %3ld %3ld %3ld %s", f, d, c, e, f < d && d <= c && c < e ? "" : "Error"); long q = gcd(d, f); long r = gcd(c, e); long s = f/q; long t = d/q; printf("%3ld %3ld %3ld %3ld %4ld %4ld = %4ld", q, r, s, t, (q*q + r*r), (s*s + t*t), (q*q + r*r)*(s*s + t*t)); if ((q*q + r*r)*(s*s + t*t) != n) printf(" ERROR"); else { long factor = (q*q + r*r) < (s*s + t*t) ? (q*q + r*r) : (s*s + t*t); int i; for (i = 0; i < nr_factors; i++) if (factors[i] == factor) break; if (i == nr_factors) factors[nr_factors++] = factor; } printf("\n"); } int main(int argc, char *argv[]) { for (long n = 25; n <= 1000000; n += 2) { long as[N]; long bs[N]; long a = 0; long b = 1; while (b * b + a * a < n) b++; long c = 0; long g = 0; while (a < b) { if (b * b + a * a == n) { as[c] = a; bs[c] = b; if (g == 0) g = gcd(a, b); else g = gcd(g, gcd(a, b)); c++; } a++; while (b * b + a * a > n) b--; } if (c >= 2 && g == 1) { printf("%ld ", n); for (long i = 0; i < c; i++) printf(" = %ld^2 + %ld^2", bs[i], as[i]); printf("\n"); nr_factors = 0; for (long i = 0; i < c-1; i++) for (long j = i+1; j < c; j++) { if (even(as[i]) == even(as[j]) && even(bs[i]) == even(bs[j])) analyse(as[i], bs[i], as[j], bs[j], n); if (even(as[i]) == even(bs[j]) && even(bs[i]) == even(as[j])) analyse(as[i], bs[i], bs[j], as[j], n); } if (nr_factors != c-1) printf("Different %ld %ld %d %ld\n", n, c, nr_factors, g); } } return 0; }