#include<stdio.h> /* 对任给的正整数N (N≤100),寻找所有的四元组(a, b, c, d),使得a3 = b3 + c3 + d3,其中1<a, b, c, d ≤N。 暴力就完事了。 */ int main() { int N, a ,s, d, f; scanf("%d", &N); for (a = 2; a <= N; ++a) for (s = 2; s <= a; ++s) for (d = s; d <= a; ++d) for (f = d; f <= a; ++f) if (a * a * a == f * f * f + s * s * s + d * d * d) printf("Cube = %d, Triple = (%d,%d,%d)\n", a, s, d, f); return 0; }
《NOJ1007 完美立方》有1个想法