Given N, count all ‘a’ and ‘b’ that satisfy the condition a^3 + b^3 = N.
Input : N = 9 Output : 2 1^3 + 2^3 = 9 2^3 + 1^3 = 9 Input : N = 28 Output : 2 1^3 + 3^3 = 28 3^3 + 1^3 = 28
Note:- (a, b) and (b, a) are to be considered as two different pairs.
Asked in : Adobe
Implementation: Travers numbers from 1 to cube root of N. a) Subtract cube of current number from N and check if their difference is a perfect cube or not. i) If perfect cube then increment count. 2- Return count.
Below is the implementation of above approach:
For n= 1, 1 pair exists For n= 2, 1 pair exists For n= 3, 0 pair exists For n= 4, 0 pair exists For n= 5, 0 pair exists For n= 6, 0 pair exists For n= 7, 0 pair exists For n= 8, 1 pair exists For n= 9, 2 pair exists For n= 10, 0 pair exists
This article is contributed by Sahil Chhabra. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
- Program to count number of distinct Squares and Cubes upto N
- Count pairs with given sum | Set 2
- Count pairs with Odd XOR
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N
- Count pairs (i,j) such that (i+j) is divisible by A and B both
- Count of pairs of (i, j) such that ((n % i) % j) % n is maximized
- Count of pairs (x, y) in an array such that x < y
- Count of odd and even sum pairs in an array
- Count Pairs from two arrays with even sum
- Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N)
- Count pairs in array whose sum is divisible by K
- Count consecutive pairs of same elements
- Count pairs with sum as a prime number and less than n
- Count the pairs of vowels in the given string