Вот вариант с генерацией простых чисел на лету и с проверкой правильности разложения:
#!/usr/bin/python
# vim: sw=4 ts=4 expandtab ai
# coding:utf8
import sys
from operator import mul
def eratosthenes(x):
'''Yields the sequence of prime numbers via the Sieve of Eratosthenes.'''
D = {} # map composite integers to primes witnessing their compositeness
q = 2 # first integer to test for primality
while q <= x:
if q not in D:
yield q # not marked composite, must be prime
D[q*q] = [q] # first multiple of q not already marked
else:
for p in D[q]: # move each witness to its next multiple
D.setdefault(p+q, []).append(p)
del D[q] # no longer need D[q], free memory
q += 1
def razl(x):
y=[]
for i in eratosthenes(x):
while not x % i and x != 1:
y.append(i)
x /= i
if x == 1:
break
return y
num = int(sys.argv[1])
res = razl(num)
print res, reduce(mul, res, 1) == num