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 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between Sum of Cubes and Sum of First N Natural Numbers
- Program to count number of distinct Squares and Cubes upto N
- Count cubes of size K inscribed in a cube of size N
- Sum of cubes of first n even numbers
- Sum of cubes of first n odd natural numbers
- Sum of cubes of even and odd natural numbers
- Squared triangular number (Sum of cubes)
- Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1
- Sum of all Perfect Cubes lying in the range [L, R] for Q queries
- Sum of cubes of all Subsets of given Array
- Sum of alternating sign cubes of first N Natural numbers
- Minimum value of K such that sum of cubes of first K natural number is greater than equal to N
- Check if a number can be represented as sum of two consecutive perfect cubes
- Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N)
- Count of pairs in an array whose sum is a perfect square
- Count pairs in array whose sum is divisible by K
- Given two arrays count all pairs whose sum is an odd number
- Count of pairs in an Array whose sum is a Perfect Cube
- Count of pairs in an Array whose sum is Prime
- Count all pairs of divisors of a number N whose sum is coprime with N