fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. void printCombs2(int n, int k) {
  5. int limit = ceil(sqrt(n));
  6. for (int i = 1; i < limit; i++) {
  7. for (int j = i; j < limit; j++) {
  8. if (i*i + j*j == n) {
  9. // printf("%d, %d, %d\n", i, j, k);
  10. printf("%d, %d, %d ==> %d+%d+%d=%d\n", i, j, k, i*i, j*j, k*k, i*i+j*j+k*k);
  11. }
  12. }
  13. }
  14. }
  15.  
  16. void printCombs(int n) {
  17. printf("combs(%d):\n", n);
  18. int limit = ceil(sqrt(n));
  19. for (int i = 1; i < limit; i++) {
  20. for (int j = i; j < limit; j++) {
  21. if (i*i + j*j == n) {
  22. // printf("%d, %d\n", i, j);
  23. printf("%d, %d ==> %d+%d=%d\n", i, j, i*i, j*j, i*i+j*j);
  24. printCombs2(i*i, j);
  25. printCombs2(j*j, i);
  26. }
  27. }
  28. }
  29. puts("");
  30. }
  31.  
  32. int main(void) {
  33. printCombs(100);
  34. printCombs(1000);
  35. printCombs(10000);
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
combs(100):
6, 8 ==> 36+64=100

combs(1000):
10, 30 ==> 100+900=1000
6, 8, 30 ==> 36+64+900=1000
18, 24, 10 ==> 324+576+100=1000
18, 26 ==> 324+676=1000
10, 24, 18 ==> 100+576+324=1000

combs(10000):
28, 96 ==> 784+9216=10000
60, 80 ==> 3600+6400=10000
36, 48, 80 ==> 1296+2304+6400=10000
48, 64, 60 ==> 2304+4096+3600=10000