bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc040.c (1796B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Ramanujan number (1729) is the smallest number that can be
      9 expressed as sum of cubes in two different ways - 1729 can be
     10 expressed as 1^3 + 12^3 and 9^3 + 10^3. Write a program to print all such
     11 numbers up to a reasonable limit. */
     12 /* Let Us C, Chap- 6, Page - 106, Qn No.: B(g) */
     13 
     14 #include <stdio.h>
     15 
     16 #define limit 100000
     17 #define max_base 47
     18 
     19 int main()
     20 {
     21 
     22     long long sum1, sum2;
     23     int count = 0;
     24 
     25     printf("Ramanujan numbers : \n");
     26 
     27     int found_match;
     28 
     29     for (int a = 1; a <= max_base; a++)
     30     {
     31         for (int b = a + 1; b <= max_base; b++)
     32         {
     33             sum1 = (long long)a * a * a + (long long)b * b * b;
     34             if (sum1 > limit)
     35             {
     36                 break;
     37             }
     38 
     39             found_match = 0;
     40 
     41             for (int c = a + 1; c <= max_base; c++)
     42             {
     43                 if (found_match)
     44                 {
     45                     break;
     46                 }
     47                 for (int d = c + 1; d <= max_base; d++)
     48                 {
     49                     sum2 = (long long)c * c * c + (long long)d * d * d;
     50                     if (sum2 > sum1)
     51                     {
     52                         break;
     53                     }
     54                     if (sum1 == sum2)
     55                     {
     56                         count++;
     57                         printf("(%d.) %lld = %d^3 + %d^3 = %d^3 + %d^3\n", count, sum1, a, b, c, d);
     58 
     59                         found_match = 1;
     60                         break;
     61                     }
     62                 }
     63             }
     64         }
     65     }
     66 
     67     printf("-------------------------------\n");
     68     printf("Search complete.");
     69 
     70     return 0;
     71 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror