mirror of
https://github.com/python/cpython.git
synced 2024-12-12 19:33:52 +08:00
Add more examples to the recipe docs (GH-106782)
Demonstrate that factor() works for large composites and large primes.
This commit is contained in:
parent
22980dc7c9
commit
e2ec0bad67
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user