1. .......Algorithm to find the first n Hardy-Ramanujan numbers....

since 1729 is the least .....

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

G-Do 19 Junior Poster

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:

1^3+12^3

- or alternatively, to the sum:

9^3+10^3

- 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!

ram.patil 0 Newbie Poster

tsmc -3 Newbie Poster

Hi,

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

Good luck.

Edited by Ezzaral because: * Snipped url. No promotion. *

TrustyTony 888 pyMod Team Colleague Featured Poster

Be a part of the DaniWeb community

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