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.
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Numbers within a range that can be expressed as power of two numbers
- Numbers less than N which are product of exactly two distinct prime numbers
- Count numbers which can be constructed using two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Count numbers which are divisible by all the numbers from 2 to 10
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- 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
- Sum of first n even numbers
- Add two numbers using ++ and/or --
- Decagonal Numbers
- Hailstone Numbers
- Undulating numbers