The nth Taxicab number Taxicab(n), also called the n-th Hardy-Ramanujan number, is defined as the smallest number that can be expressed as a sum of two positive cube numbers in n distinct ways.
The most famous taxicab number is 1729 = Taxicab(2) = (1 ^ 3) + (12 ^ 3) = (9 ^ 3) + (10 ^ 3).
Given a number N, print first N Taxicab(2) numbers.
Input : N = 1 Output : 1729 Explanation : 1729 = (1 ^ 3) + (12 ^ 3) = (9 ^ 3) + (10 ^ 3) Input : N = 2 Output : 1729 4104 Explanation : 1729 = (1 ^ 3) + (12 ^ 3) = (9 ^ 3) + (10 ^ 3) 4104 = (16 ^ 3) + (2 ^ 3) = (15 ^ 3) + (9 ^ 3)
We try all numbers one by one and check if it is a taxicab number. To check if a number is Taxicab, we use two nested loops :
In outer loop, we calculate cube root of a number.
In inner loop, we check if there is a cube-root which yield the result.
1 1729 2 4104 3 13832 4 20683 5 32832
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Numbers within a range that can be expressed as power of two numbers
- Check if a given pair of Numbers are Betrothed numbers or not
- Numbers less than N which are product of exactly two distinct prime numbers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Count numbers which can be constructed using two numbers
- Count numbers which are divisible by all the numbers from 2 to 10
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Self Numbers
- Add two numbers using ++ and/or --
- D Numbers
- Sum of first n even numbers
- Sum of first n natural numbers
- Happy Numbers
- LCM of two large numbers