/usr/share/doc/python3-pyutilib/examples/pyro/factor.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import sys
from math import sqrt
import pyutilib.pyro
if sys.version_info >= (3,0):
xrange = range
def factorize(n):
def isPrime(n):
return not [x for x in xrange(2,int(sqrt(n))+1) if n%x == 0]
primes = []
candidates = xrange(2,n+1)
candidate = 2
while not primes and candidate in candidates:
if n%candidate == 0 and isPrime(candidate):
primes = primes + [candidate] + factorize(n/candidate)
candidate += 1
return primes
class FactorWorker(pyutilib.pyro.TaskWorker):
def process(self,data):
print "factorizing",data,"-->",
sys.stdout.flush()
res = factorize(int(data))
print res
return res
|