galois.perfect_power(n: int) tuple[int, int]

Returns the integer base $$c$$ and exponent $$e$$ of $$n = c^e$$. If $$n$$ is not a perfect power, then $$c = n$$ and $$e = 1$$.

Parameters:
n: int

An integer.

Returns:

• The potentially composite base $$c$$.

• The exponent $$e$$.

Examples

Primes are not perfect powers because their exponent is 1.

In : n = 13

In : galois.perfect_power(n)
Out: (13, 1)

In : galois.is_perfect_power(n)
Out: False


Products of primes are not perfect powers.

In : n = 5 * 7

In : galois.perfect_power(n)
Out: (35, 1)

In : galois.is_perfect_power(n)
Out: False


Products of prime powers where the GCD of the exponents is 1 are not perfect powers.

In : n = 2 * 3 * 5**3

In : galois.perfect_power(n)
Out: (750, 1)

In : galois.is_perfect_power(n)
Out: False


Products of prime powers where the GCD of the exponents is greater than 1 are perfect powers.

In : n = 2**2 * 3**2 * 5**4

In : galois.perfect_power(n)
Out: (150, 2)

In : galois.is_perfect_power(n)
Out: True


Negative integers can be perfect powers if they can be factored with an odd exponent.

In : n = -64

In : galois.perfect_power(n)
Out: (-4, 3)

In : galois.is_perfect_power(n)
Out: True


Negative integers that are only factored with an even exponent are not perfect powers.

In : n = -100

In : galois.perfect_power(n)
Out: (-100, 1)

In : galois.is_perfect_power(n)
Out: False