How to check if a integer is a power of some integer? Given a integer $n$, we want to know if $n=m^k$ for some $m$ and $k>1$. What is the fastest method? (Suppose the factors of $n$ are not given).
The best method I can think of is to try to calculate $n^\frac{1}{k}$ to a certain precision, for $k$ from $2$ to $\log_2 n$. Determine if $n^\frac{1}{k}$ is a integer by test if $\lfloor n^\frac{1}{k} \rfloor ^k = n$.
 A: Like Jonas Meyer said, the mathoverflow post contains all the information.
The problem can be solved in almost linear time by this paper.
A: Here's a Python 3.8 function that gives a Boolean (True/False) answer to your question: is y a power of x. This can be run in a loop where x can get different values (m) since you don't know the values of both m and k.
 def check(x,y):
        if (x == 1): return (y == 1)
        pow = 1
        while (pow < y): pow = pow * x
        return (pow == y)
        #the time complexity here is O(Log (y to base x))
        #we can make this work in O(Log Log y)...
        '''
        The idea is to do squaring of power instead of multiplying
        it with x, i.e., compare y with x^2, x^4, x^8, …etc. If x 
        becomes equal to y, return true. If x becomes more than y,
        then we do a binary search for the power of x between previous
        power and current power, i.e., between x^i and x^(i/2)
        '''

    

I found a coding problem that required this little snippet of code...
Personally, I also needed to know the values of m and k and not just check whether the number n was a power of some number m. What I used was:
from math import log
def check(x,y):
    res1 = log(y)//log(x); res2 = log(y)/log(x);
    return [1,res1] if(res1 == res2) else [0];
for _ in range(int(input())): #number of test cases
    x,y = map(int,input().split()) 
    if(x == y): print(1,1)
    elif(x < y and y/x == int(y/x)):
        for i in range(2,int(y/x) + 1):
            if(check(i,int(y/x))[0] == 1): print(1,int(y/x));break
        else: print(0,0)
    else: print(0,0)

Here, I was required to find two positive integers a and b such that when x is multiplied by b "a" number of times (basically, n*(b**a)), we get the number y.
printing "0 0" here means there exists no such value of a and b.
for x < y, if y/x is an integer, then there exists some value for a and b
There can, of course, be multiple such values. Like, 26 == 43 == 8**6.
With respect to your question, here n = x/y. we need to find m and k, which here are b and a respectively.
The simplest solution is 1, int(x/y). That is, putting m = n and k = 1.
Otherwise, we can use m = res1 (from check function, res1 = log(y)//log(x)) and k = i, where i is the iterator (increments on every step of the loop)
for i in range(2,int(y/x) + 1):
    arr = check(i,int(y/x))
    if(arr[0] == 1): print(int(arr[1]),i);break
else: print(0,0)

