Check if a number can be expressed as x^y (x raised to power y) - GeeksforGeeks
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 xy where y > 1 and x > 0. x and y both are integers.
Examples:
Input: n = 8 Output: true 8 can be expressed as 23 Input: n = 49 Output: true 49 can be expressed as 72 Input: n = 48 Output: false 48 can't be expressed as xy
We strongly recommend you to minimize your browser and try this yourself first.
The idea is simple try all numbers x starting from 2 to square root of n (given number). For every x, try x^y where y starts from 2 and increases one by one until either x^y becomes n or greater than n.
Read full article from Check if a number can be expressed as x^y (x raised to power y) - GeeksforGeeks
No comments:
Post a Comment