[3.12] Sync factor() recipe with main branch (gh-110231)

This commit is contained in:
Raymond Hettinger 2023-10-02 14:19:46 -05:00 committed by GitHub
parent 25bf0564c4
commit 221c8d64e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1119,9 +1119,7 @@ The following recipes have a more mathematical flavor:
# factor(1_000_000_000_000_007) --> 47 59 360620266859
# factor(1_000_000_000_000_403) --> 1000000000000403
for prime in sieve(math.isqrt(n) + 1):
while True:
if n % prime:
break
while not n % prime:
yield prime
n //= prime
if n == 1: