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

Returns the integer base \(c\) and exponent \(e\) of \(n = c^e\).

If \(n\) is a not 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 [1]: n = 13

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

In [3]: galois.is_perfect_power(n)
Out[3]: False

Products of primes are not perfect powers.

In [4]: n = 5 * 7

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

In [6]: galois.is_perfect_power(n)
Out[6]: False

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

In [7]: n = 2 * 3 * 5**3

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

In [9]: galois.is_perfect_power(n)
Out[9]: False

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

In [10]: n = 2**2 * 3**2 * 5**4

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

In [12]: galois.is_perfect_power(n)
Out[12]: True

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

In [13]: n = -64

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

In [15]: galois.is_perfect_power(n)
Out[15]: True

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

In [16]: n = -100

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

In [18]: galois.is_perfect_power(n)
Out[18]: False