Created
January 14, 2023 18:44
-
-
Save jepler/faa3b20618ec53efd6e138edec7ad5dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import sys | |
def erat2(): | |
D = {} | |
yield 2 | |
for q in itertools.islice(itertools.count(3), 0, None, 2): | |
p = D.pop(q, None) | |
if p is None: | |
D[q * q] = q | |
yield q | |
else: | |
x = p + q | |
while x in D or not (x & 1): | |
x += p | |
D[x] = p | |
for arg in sys.argv[1:]: | |
i = int(arg) | |
print(end=f"{i}:") | |
for p in erat2(): | |
if p * p > i: | |
break | |
while i % p == 0: | |
print(end=f" {p}") | |
i //= p | |
if i > 1: | |
print(f" {i}") | |
else: | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment