Given a number n, we need to check if it can be expressed as 2x + 2y or not . Here x and y can be equal.
Input : 24 Output : Yes Explanation: 24 can be expressed as 24 + 23 Input : 13 output : No Explanation: It is not possible to express 13 as sum of two powers of 2.
If we take few examples, we can notice that a number can be expressed in the form of 2^x + 2^y if the number is already a power of 2 ( for n > 1 ) or the remainder we get after subtracting previous power of two from the number is also a power of 2.
Below is the implementation of above idea
16 4 No
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if a number can be expressed as a^b | Set 2
- Check if a number can be expressed as power | Set 2 (Using Log)
- Check if a number can be expressed as x^y (x raised to power y)
- Check if a number can be expressed as sum two abundant numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a number can be expressed as a product of exactly K prime divisors
- Check whether a number can be expressed as a product of single digit numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if N can be expressed as product of 3 distinct numbers
- Check if an integer can be expressed as a sum of two semi-primes
- Number expressed as sum of five consecutive integers
- N expressed as sum of 4 prime numbers
- Elements of Array which can be expressed as power of some integer to given exponent K
- Elements of Array which can be expressed as power of prime numbers
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
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.
Improved By : Chandan_Kumar