0

So let's say I have a number, $n$, which is $327429$. I want to find which power of a number will result in this number. For example, I have the equation: $6^4$. This results in $1296$. Now what I want to do, is to find which power will result in my number, $n$ - let's call the base $b$ and the exponent $e$. So my solution to the problem would look something like $n = b^e$.

The base and exponent can be anything, as long as they are not decimals - they need to be integers with no decimal places. I'm planning to implement this in C++ (though I'm sure this would not really qualify as a coding question.)

Restating the Problem: I need to find $b$ and $e$ and I already know $n$.

How would I go about doing this?

Gary
  • 36,640
  • 1
    Power detection is a special case of the linked post (see the algorithm of Bernstein linked there). – Bill Dubuque Mar 28 '22 at 00:00
  • 1
    The answer you accepted using prime factorization is only usable for very small numbers because factorization is hard for larger numbers. But the algorithm I linked above doesn't suffer from this problem (it's essentially linear time). So your acceptance of that answer may mislead future readers. – Bill Dubuque Mar 28 '22 at 01:30