fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int limit = 20;
  5. int numbers_found = 0;
  6. printf("searching for ramanujan numbers with components up to %d...\n", limit);
  7.  
  8. for(int a=1; a<=limit; a++){
  9. for(int b=a; b<=limit; b++){
  10. int sum1 = (a*a*a) + (b*b*b);
  11. for(int c=a+1; c<=limit; c++){
  12. for(int d=c; d<=limit; d++){
  13. int sum2 = (c*c*c) + (d*d*d);
  14. if(sum1 == sum2){
  15. printf("\n found one! --> %d\n", sum1);
  16. printf(" As: %d^3 + %d^3\n", a, b);
  17. printf(" And as: %d^3 + %d^3\n", c, d);
  18. numbers_found++;
  19. }
  20. }
  21. }
  22. }
  23. }
  24.  
  25. if(numbers_found == 0){
  26. printf("No ramanujan number is found within the limit\n");
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5316KB
stdin
1729
stdout
searching for ramanujan numbers with components up to 20...

 found one! --> 1729
 As: 1^3 + 12^3
 And as: 9^3 + 10^3

 found one! --> 4104
 As: 2^3 + 16^3
 And as: 9^3 + 15^3