def quad_primes(limit): res = [] for a in xrange(-limit+1,limit): for b in [1] + primes.generate(limit): res.append((seq(a,b), (a, b), a*b)) res.append((seq(a,-b), (a, -b), a*b)) return max(res)
def solve(): # Prime Number Theorem: # Roughly speaking, the prime number theorem states that if you randomly # select a number nearby some large number N, the chance of it being prime # is about 1 / ln(N), where ln(N) denotes the natural logarithm of N. For # example, near N = 10,000, about one in nine numbers is prime, whereas # near N = 1,000,000,000, only one in every 21 numbers is prime. return primes.generate(10000)[1001]
def factor_count(n): """ returns a dictionary of {factor: times_occuring} for the number n """ ret = collections.defaultdict(int) for p in itertools.takewhile(lambda p: p<=n, primes.generate()): while not n % p: ret[p] += 1 n = n // p return ret
def run(): print(sum(itertools.takewhile(lambda n:n<2e6, primes.generate())))
def iter_factors(n): for p in itertools.takewhile(lambda p: p<=n, primes.generate()): while not n % p: yield p n = n // p
#!/usr/bin/python # https://projecteuler.net/problem=10 # Find the sum of all the primes below two million. from primes import generate sum = 0L n = 2000000 for prime in generate(): if prime < n: sum += prime else: print sum break
import primes as prim print prim.generate(10) limit=100 count=0 yaks='' for p in prim.P: yaks=yaks+ ''' ####################################### ''' yaks=yaks+ str(p) yaks=yaks+ ''' ####################################### ''' yaks=yaks+ str(prim.YaksicPrimes(p)) count+=1 if count>limit: f = open('YaksicPrimes.txt', 'w') f.write(yaks) break
def test_primes(self): for x in imap(eq, self.primes, generate()): self.assertTrue(x)
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are there below one million? """ from collections import deque from primes import generate, check as isprime def is_circular_prime(p): rotations = len(str(p)) prime = deque(str(p)) for x in range(rotations): prime_int = int("".join(prime)) if not isprime(prime_int): return False prime.rotate(1) return True primes = generate(1000000) count = 0 for i, prime in enumerate(primes): if prime and is_circular_prime(i): count += 1 print(count)
#!/usr/bin/python # https://projecteuler.net/problem=7 # What is the 10,001st prime number? from primes import generate for n, prime in enumerate(generate()): if n == 10000: print prime break
def nth_prime(n): for idx, p in enumerate(primes.generate(), start=1): if idx==n: return p