示例#1
0
文件: p179.py 项目: icot/euler
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
示例#2
0
文件: dbload.py 项目: icot/euler
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
示例#3
0
文件: p179.py 项目: icot/euler
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)
示例#4
0
文件: p12.py 项目: icot/euler
#!/usr/bin/python

import utils


if __name__ == "__main__":
    primes = utils.FastPrimeSieve(1000000)
    triangle = utils.triangle_gen()
    n = triangle.next()
    ndivisors = 1
    n = n+1
    while ndivisors <100:
        n = n+1
        if n not in primes:
            ndivisors = utils.ndivisors(n)
    print n, ndivisors