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
- Find two numbers such that difference of their squares equal to N
- Smallest N digit number which is a perfect fourth power
- Given two numbers as strings, find if one is a power of other
- Sum of fourth powers of first n odd natural numbers
- Sum of fourth powers of the first n natural numbers
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Count numbers whose difference with N is equal to XOR with N
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Find all factorial numbers less than or equal to n
- Find K numbers with sum equal to N and sum of their squares maximized
- Find N distinct numbers whose bitwise Or is equal to K
- Find maximum product of digits among numbers less than or equal to N
- Find the sum of power of bit count raised to the power B
- Find power of power under mod of a prime
- Highest power of 2 less than or equal to given number
- Highest power of 2 less than or equal to given Integer
- Smallest power of 4 greater than or equal to N
- Smallest power of 2 greater than or equal to n
- Highest and Smallest power of K less than and greater than equal to N respectively
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.