Add more examples to the recipe docs (GH-106782)

Demonstrate that factor() works for large composites and large primes.
This commit is contained in:
Raymond Hettinger 2023-07-15 14:43:09 -05:00 committed by GitHub
parent 22980dc7c9
commit e2ec0bad67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1045,6 +1045,8 @@ The following recipes have a more mathematical flavor:
def factor(n):
"Prime factors of n."
# factor(99) --> 3 3 11
# 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:
quotient, remainder = divmod(n, prime)