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

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

Re: Hardy-ramanujan number 80 80

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!

Re: Hardy-ramanujan number 80 80

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

Re: Hardy-ramanujan number 80 80


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

Good luck.

Re: Hardy-ramanujan number 80 80

Do not high jack dead and buried threads, this is by the way Python not Java forum. Refer to by Python function I made for it today: http://www.daniweb.com/software-development/python/code/358014/1526449#post1526449, It is "slightly shorter" than "your" Java version.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.