Given an integer N, the task is to find two non-negative integers X and Y such that X4 – Y4 = N. If no such pair exists, print -1.
Input: N = 15
Output: X = 2, Y = 1
X4 – Y4 = (2)4 – (1)4 = (16) – (1) = 15
Input: N = 10
No such value of X and Y are there which satisfy the condition.
To solve the problem mentioned above, we have to observe that we need to find the minimum and the maximum values of x and y that is possible to satisfy the equation.
- The minimum value for the two integers can be 0 since X & Y are non-negative.
- The maximum value of X and Y can be ceil(N(1/4)).
- Hence, iterate over the range [0, ceil(N(1/4))] and find any suitable pair of X and Y that satisfies the condition.
Below is the implementation of the above approach:
x = 2, y = 1
Time Complexity: O(sqrt(N))
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.
- Sum of fourth power of first n even natural numbers
- Smallest N digit number which is a perfect fourth power
- Sum of fourth powers of the first n natural numbers
- Sum of fourth powers of first n odd natural numbers
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Find power of power under mod of a prime
- Find the sum of power of bit count raised to the power B
- Numbers within a range that can be expressed as power of two numbers
- Check if given number is a power of d where d is a power of 2
- Compute power of power k times % m
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Count numbers whose difference with N is equal to XOR with N
- Given two numbers as strings, find if one is a power of other
- Find N distinct numbers whose bitwise Or is equal to K
- Find two numbers such that difference of their squares equal to N
- Minimum element whose n-th power is greater than product of an array of size n
- Array containing power of 2 whose XOR and Sum of elements equals X
- Count pairs in Array whose product is a Kth power of any positive integer
- Count of pairs whose bitwise AND is a power of 2
- Count of elements which cannot form any pair whose sum is power of 2
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.