diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 6ef67396026..5fd948c2a83 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -4963,6 +4963,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): (2, 2) sage: 256.perfect_power() (2, 8) + + Test small powers of even numbers that are not a power of 2 + (see :issue:`40846`):: + + sage: (26**2).perfect_power() + (26, 2) """ cdef long n # Fast PARI-free path @@ -4974,7 +4980,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): if not (n & 1): if mpz_popcount(self.value) == 1: return smallInteger(2), smallInteger(mpz_sizeinbase(self.value, 2) - 1) - if n < 1000: + elif n < 1000: if _small_primes_table[n >> 1]: return self, one