galois.perfect_power¶
- 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\).
See also
Examples
Primes are not perfect powers because their exponent is 1.
In [1]: galois.perfect_power(13) Out[1]: (13, 1) In [2]: galois.is_perfect_power(13) Out[2]: False
Products of primes are not perfect powers.
In [3]: galois.perfect_power(5*7) Out[3]: (35, 1) In [4]: galois.is_perfect_power(5*7) Out[4]: False
Products of prime powers where the GCD of the exponents is 1 are not perfect powers.
In [5]: galois.perfect_power(2 * 3 * 5**3) Out[5]: (750, 1) In [6]: galois.is_perfect_power(2 * 3 * 5**3) Out[6]: False
Products of prime powers where the GCD of the exponents is greater than 1 are perfect powers.
In [7]: galois.perfect_power(2**2 * 3**2 * 5**4) Out[7]: (150, 2) In [8]: galois.is_perfect_power(2**2 * 3**2 * 5**4) Out[8]: True
Negative integers can be perfect powers if they can be factored with an odd exponent.
In [9]: galois.perfect_power(-64) Out[9]: (-4, 3) In [10]: galois.is_perfect_power(-64) Out[10]: True
Negative integers that are only factored with an even exponent are not perfect powers.
In [11]: galois.perfect_power(-100) Out[11]: (-100, 1) In [12]: galois.is_perfect_power(-100) Out[12]: False
Last update:
Apr 21, 2022