Skip to content

Commit

Permalink
preserve prime^2 for use in factoring
Browse files Browse the repository at this point in the history
  • Loading branch information
glyphobet committed Jan 18, 2012
1 parent 15143df commit 61865bd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sieve.py
Expand Up @@ -18,14 +18,14 @@ def relatively_prime(n):
while True:
n += 1
if relatively_prime(n):
yield n
primes.append((n, n**2))
yield primes[-1]


def factor(n):
"""Factor an integer into its unique prime factorization."""
for p in primes():
if p > n:
for p, p2 in primes():
if n < p2:
break
while n % p == 0:
yield p
Expand Down

0 comments on commit 61865bd

Please sign in to comment.