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 :
- If the indices is 1, then you just have the number itself. For example, 5^1 = 5
- If the indices is 0, then you get 1. For example, 5^0 = 1
- Exponents make it easier to write and use many multiplications
- Negative exponent means how many times to divide one by the number.For example, 5^-1 = 1 /5 = 0.2
How we check if a number is power of y for a given integer x ?
Given two positive numbers x and y, check if y is a power of x or not.
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.
True False True False
Time complexity of above solution is O(Logxy)
Basic Program related to Power :
- Find unit digit of x raised to power y
- Check if a number can be expressed as x^y (x raised to power y)
- Find the multiple of x which is closest to a^b
- All possible numbers of N digits and base B without leading zeros
- Check if a number can be expressed as a^b | Set 2
- Write you own Power without using multiplication(*) and division(/) operators
More problems related to Powers :
- Total number of subsets in which the product of the elements is even
- Sum of first N natural numbers which are not powers of K
- GCD of a number raised to some power and another number
- Largest N digit number divisible by given three numbers
- Check whether a given Number is Power-Isolated or not
- Check if given number is a power of d where d is a power of 2
- Find power of power under mod of a prime
- Compute power of power k times % m
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Mathematics | Mean, Variance and Standard Deviation
- Power Set
- Mathematics | Graph theory practice questions
- Perfect power (1, 4, 8, 9, 16, 25, 27, ...)
- Fibonacci Power
- Power of a lens
- Program for Picard's iterative method | Computational Mathematics
- Find whether a given number is a power of 4 or not
- Program to find whether a no is power of two
- Find whether a given integer is a power of 3 or not
- Find value of y mod (2 raised to power x)
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.