1. .......Algorithm to find the first n Hardy-Ramanujan numbers....
since 1729 is the least .....

I request to post the solution for this............

11 Years
Discussion Span
Last Post by pyTony

Hi ram.patil,

A Hardy-Ramanujan number is a number which can be expressed as the sum of two positive cubes in exactly two different ways. For example, 1729 is equal to the sum:


- or alternatively, to the sum:


- but not to any other sums of positive cubes. Let's think about a general strategy for collecting the first n of these numbers. You will need to store the numbers in an extendable data structure, such as a list. You will also need to keep trying to find numbers until you have found n of them, appending valid Hardy-Ramanujan numbers to the list as you go. To implement this, you could do a while loop which keeps looking for Hardy-Ramanujan numbers until the length of the list is n. Does that make sense?

To find the numbers themselves, you could always try the naive approach: beginning with 1729, check each number. Subtract successive integer cubes from the number and see if the difference is a cube. This could be represented by a for loop nested inside your while loop. During the for loop, keep track of every time the difference is a cube. If, when the for loop completes, the difference has been a cube only twice, you know that the number is a Hardy-Ramanujan number, and can be added to the list.

Hope this helps!


sir , i'm very glad to hear this from u ... i tried this method and i'm successful in getting the n such numbers.



U can find the list of Ramanujan numbers in a given range using the following program,

Good luck.

Edited by Ezzaral: Snipped url. No promotion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.