Ramanujan Number or Taxicab Number in Java
In this section, we will learn what is Ramanujan number (or Hardy-Ramanujan number) and how to check whether the number is Ramanujan or not through a Java program.
In mathematics, the Ramanujan number is a magical number. It can be defined as the smallest number which can be expressed as a sum of two positive integer cubes in n-distinct ways. It is also known as Taxicab number. It is denoted by Ta. The most popular taxicab number is 1729.
The number 1729 is related to a taxi. Once Ramanujan was admitted in the hospital and G.H. Hardy (British mathematician) arrived for a visit by taxi. The number of the taxi in which he traveled was 1729. He remarked that the number of my taxi seems a dull number.
After hearing the words of Hardy, Ramanujan replied, No Hardy! It is a very interesting number. Hardy asked, how? Then, Ramanujan replied, the number 1729 is the smallest number expressible as the sum of two cubes in two distinct ways. Since then it is known as the Ramanujan or Hardy-Ramanujan or Taxicab number. Let's check the Ramanujan statement.
Some other examples of Ramanujan numbers are:
It is also possible that a taxicab number may expressible as the sum of two cubes in three distinct ways. For example, the number 15,170,835,645 is equals to:
It is also possible that a taxicab number may expressible as the sum of two cubes in four distinct ways. For example, the number 1,801,049,058,342,701,083 is equals to:
It is difficult to determine the Ta(N) because the numbers get very large
Approaches to Find Ramanujan Number
There are two approaches to find the Ramanujan number. Let's understand each one by one with examples.
A magical number that is equal to the product of the sum of all digits of a number and reverse of the sum. Let's follow the steps to find the Ramanujan number.
Step 1: Read an integer from the user.
Step 2: Sum up the individual digits.
Step 3: Find the reverse of the sum.
Step 4: Calculate the product of the original number and reversed number.
If the product is the same as the original number (that we have entered), the number is a Ramanujan number, else not. Let's understand it through an example.
Suppose, we want to check the number 1458 is a Ramanujan number or not.
We get the same number that we have taken. Hence, the given number is a Ramanujan or taxicab number.
Let's implement the above approaches in a Java program.
It this approach, the given number is expressible as the sum of two cubes in N different ways. For example:
1729= 103+93= 13+123
Ramanujan Number Program in Java
Enter a number you want to check: 1729 1729 is a Ramanujan Number.
Enter a number you want to check: 1428 1428 is not a Ramanujan Number.
Let's create another program that finds the Ramanujan number between specified range.
Ramanujan Number between 1000 to 1000000: 1458 1729
Ramanujan Number between 1 to 100000000: 1 81 1458 1729