Skip to content

Instantly share code, notes, and snippets.

@eFrane
Created January 26, 2012 22:10
Show Gist options
  • Save eFrane/1685422 to your computer and use it in GitHub Desktop.
Save eFrane/1685422 to your computer and use it in GitHub Desktop.
simple prime factorization in python
import math
def prime(n):
i = 2
while i < 0.5 + math.sqrt(n):
if n % i == 0:
return False
i+=1
return True
def primefactors(n):
f = []
for i in range(n/2, 0, -1):
if prime(i) and n % i == 0:
f.append(i)
return f
i,n = 0,1
while n < 10:
i += 1
f = primefactors(i)
n = len(f)
print i,f,n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment