def main2(N): print "Generating primes" maxp = int(sqrt(N)) + 1 primes = FastPrimeSieve(maxp) print "Computing factors" prev = 0 total = 0 for n in xrange(2,int(1e7) +1): prime_factors = trial_division(n, primes) ndivs = ndivisors(n, prime_factors) if ndivs == prev: total += 1 prev = ndivs if n % 100000 == 0: print n print total
def worker_file(a, b, primes): with gzip.open("dump.bin", "ab", compresslevel=3) as fp: buf = [] for n in xrange(a, b): prime_factors = trial_division(n, primes) num_factors = len(prime_factors) data = { "n": n, "factors": prime_factors, "ndivisors": ndivisors(n, prime_factors), "nfactors": num_factors, "max_factor": max(prime_factors), "primality": num_factors == 1, } buf.append(data) cPickle.dump(buf, fp, protocol=2) return b - a
def worker_db(a,b, primes): with Connection('localhost') as con: db = con['integers'] col = db['misc'] buf = [] for n in xrange(a, b): prime_factors = trial_division(n, primes) num_factors = len(prime_factors) data = {'n' : n, 'factors' : prime_factors, 'ndivisors' : ndivisors(n, prime_factors), 'nfactors' : num_factors, 'max_factor': max(prime_factors), 'primality' : num_factors == 1} buf.append(data) col.insert(buf) con.disconnect() return (b-a)