![]() |
VOOZH | about |
The power of a number says how many times to use the number in a multiplication. Powers are also called Exponents or Indices. For example, 8^2 could be called "8 to the power 2" or "8 to the second power", or simply "8 squared".
Some interesting fact about Power :
How we check if a number is power of y for a given integer x ?
Naive solution:
Given two positive numbers x and y, check if y is a power of x or not.
Examples :
Input: x = 10, y = 1 Output: True Input: x = 10, y = 1000 Output: True Input: x = 10, y = 1001 Output: False
Approach : A simple solution is to repeatedly compute powers of x. If a power becomes equal to y, then y is a power, else not.
Output:
True False True False
Time complexity of above solution is O(Logxy)
Auxiliary Space: O(1)
Basic Program related to Power :
More problems related to Powers :