# Integer Logarithm

## Mathematica, 474543 29 bytes SBCS

If[NumberQ[c=#~Log~#2],c,-1]&


You can try it online!

Thanks to @J42161217 for saving me a total of 16 bytes!!

## Python 3, 103 101 97 bytes

Saved 2 bytes thanks to Kevin Cruijssen!!!
Saved 4 bytes thanks to Value Ink!!!

from math import*
def f(a,b):
l=log(b,a)
n,m=l.as_integer_ratio()
return -1if a**n-b**m else l


Try it online!

## Charcoal, 88 82 bytes

≔Ｅθ⟦⟧ζ≔²ηＷ⊖⌈θ¿⌊﹪θη≦⊕ηＵＭθ⎇﹪κηκ∧⊞Ｏ§ζλη÷κηＦζＦι⊞υκＵＭυＥζ№λιＵＭυ÷ι⊟Φ⊕⌈ι∧λ¬⌈﹪ιλ¿›⌈υ⌊υ-1Ｉ⊟υ


Try it online! Link is to verbose version of code. Takes input as a list in [value, base] order and outputs numerator and denominator. Edit: Saved 6 bytes by simplifying my check for exclusive factors. Explanation:

≔Ｅθ⟦⟧ζ≔²ηＷ⊖⌈θ¿⌊﹪θη≦⊕ηＵＭθ⎇﹪κηκ∧⊞Ｏ§ζλη÷κη


Factorise both numbers by trial division.

ＦζＦι⊞υκ


Collect the factors from both inputs, in case some factors are only present in one of them.

ＵＭυＥζ№λιＵＭυ÷ι⊟Φ⊕⌈ι∧λ¬⌈﹪ιλ


Divide the multiplicity of each factor in both the base and the value by their GCD.

¿›⌈υ⌊υ-1


If this is not unique then output -1.

Ｉ⊟υ


If it is unique then output it.