Python: Find an integer exponent x such that a^x = n
Find Integer Exponent
Write a Python program to find an integer exponent x such that a^x = n.
Input: a = 2 : n = 1024 Output: 10 Input: a = 3 : n = 81 Output: 4 Input: a = 3 : n = 1290070078170102666248196035845070394933441741644993085810116441344597492642263849 Output: 170
Visual Presentation:
Sample Solution:
Python Code:
Sample Output:
a = 2 : n = 1024 Find an integer exponent x such that a^x = n: 10 a = 3 : n = 81 Find an integer exponent x such that a^x = n: 4 a = 3 : n = 1290070078170102666248196035845070394933441741644993085810116441344597492642263849 Find an integer exponent x such that a^x = n: 170
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to compute the smallest integer exponent x such that a raised to x equals n using iterative multiplication.
- Write a Python program to determine if an integer exponent exists for a given a and n, returning -1 if not.
- Write a Python program to calculate the exponent by applying math.log and then verifying with integer rounding.
- Write a Python program to implement a loop that multiplies a repeatedly until it equals n and count the iterations as x.
Go to:
Previous: Find the numbers that are greater than 10 and have odd first and last digits.
Next: Sum of the magnitudes of the elements in the array with product signs.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.