Check if a number can be expressed as x^y (x raised to power y)
Given a positive integer n, find if it can be expressed as x^y where y > 1 and x > 0. x and y both are integers.
Input: n = 8 Output: true 8 can be expressed as 2^3 Input: n = 49 Output: true 49 can be expressed as 7^2 Input: n = 48 Output: false 48 can't be expressed as x^y
We have discussed two different approaches in below post.
The idea is find Log n in different bases from 2 to square root of n. If Log n for a base becomes integer then result is true, else result is false.
4 8 9 16 25 27 32 36 49 64 81
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.
- Check if a number can be expressed as x^y (x raised to power y)
- Check if a number can be expressed as 2^x + 2^y
- Check if a number can be expressed as a^b | Set 2
- Check if a number N can be expressed in base B
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a number can be expressed as sum two abundant 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 given number is a power of d where d is a power of 2
- 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
- Check if a large number is divisible by a number which is a power of 2
- Check if a prime number can be expressed as sum of two Prime Numbers
- Given a HUGE number check if it's a power of two.
- Check whether a given Number is Power-Isolated or not
- Check if the number is a Prime power number
- Check if a number is power of k using base changing method
- Check if ceil of number divided by power of two exist in sorted array
- Check if a number is a power of another number
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.