def __init__(self, n, failureProb = 1e-5): #total size of bit array self.n = n self.m = nextPrime((int)(-n * log(failureProb) / (log(2)**2))) self.filter = bitarray() self.filter.append(False) self.filter = self.m * self.filter self.k = (int)(self.m*(log(2))/self.n) seed() self.hashes = [(randint(0,self.m-1),randint(0,self.m-1)) for i in range(0,self.k)]
def __init__(self, n, failureProb=1e-5): #total size of bit array self.n = n self.m = nextPrime((int)(-n * log(failureProb) / (log(2)**2))) self.filter = bitarray() self.filter.append(False) self.filter = self.m * self.filter self.k = (int)(self.m * (log(2)) / self.n) seed() self.hashes = [(randint(0, self.m - 1), randint(0, self.m - 1)) for i in range(0, self.k)]
#!/usr/bin/python # https://projecteuler.net/problem=7 import primes target = 10001 val=2 for i in range(1,target): val = primes.nextPrime(val) print val
#!/usr/bin/python # https://projecteuler.net/problem=3 import primes target = 13195 target = 600851475143 factor = 2 while target>1: if target%factor==0: target/=factor else: factor = primes.nextPrime(factor) print factor
def successors((primeset, newprime)): nextprime = nextPrime(newprime) #primes(newprime).next() succs = [(primeset, nextprime)] if compatible(primeset, newprime): succs.append((primeset+[newprime], nextprime)) return succs