Ramanujan Number or Taxicab Number in JavaIn this section, we will learn what is Ramanujan number (or HardyRamanujan number) and how to check whether the number is Ramanujan or not through a Java program. Ramanujan NumberIn 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 ndistinct 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 HardyRamanujan or Taxicab number. Let's check the Ramanujan statement.
1729= 10^{3}+9^{3}=1000+729
1729= 1^{3}+12^{3}=1+1728 Some other examples of Ramanujan numbers are:
4104= 2^{3}+16^{3}=8+4096
4104= 9^{3}+15^{3}=729+3375 13832= 24^{3}+2^{3}=13824+8 13832= 18^{3}+20^{3}=5832+8000 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:
517^{3}+2468^{3}=709^{3}+2456^{3}=1733^{3}+2152^{3}
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:
92227^{3}+1216500^{3}=136635^{3}+1216102^{3}=341995^{3}+1207602^{3}==600259^{3}+1165884^{3}
It is difficult to determine the Ta(N) because the numbers get very large Approaches to Find Ramanujan NumberThere are two approaches to find the Ramanujan number. Let's understand each one by one with examples. Approach 1: 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. 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. Approach 2: It this approach, the given number is expressible as the sum of two cubes in N different ways. For example:
1729= 10^{3}+9^{3}= 1^{3}+12^{3}
Ramanujan Number Program in JavaRamanujanNumberExample1.java Output 1: Enter a number you want to check: 1729 1729 is a Ramanujan Number. Output 2: 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. RamanujanNumberExample2.java Output 1: Ramanujan Number between 1000 to 1000000: 1458 1729 Output 2: Ramanujan Number between 1 to 100000000: 1 81 1458 1729
Next TopicAdvanced Java Books in 2021
