def main(): # based on Fermat's Little Theorem r = 0 for p in take_while(primes(), lambda p: p < 1000): if p == 2 or p == 5: continue rp = multiplicative_order(10, p) if rp > r: r = rp q = p return q
from funcs import primes from math import sqrt num = 600851475143 for p in primes( int(sqrt(num)+2) )[::-1]: if num%p == 0: print p break
def main(): gen = primes() for i in range(10001): p = next(gen) return p
def main(): return sum(take_while(primes(), lambda p: p < 2000000))
from funcs import count_divisors, primes t = 0 i = 0 plist = primes( 10**4, 500 ) max_divs = 0 while True: i += 1 t += i n_div = count_divisors( t, plist ) if n_div > max_divs: print "{0} has {1} divisors".format( t, n_div ) max_divs = n_div if n_div > 500: break print t
from funcs import primes print primes(10**6,10001)[10000]
from operator import mul from funcs import primes stride=reduce( mul, primes(20) ) n = stride while True: is_div = True; for i in range(1,21): if n % i != 0: is_div = False break if is_div: break n += stride print n
from funcs import primes print sum( primes( 2*10**6 - 1 ) )
def test_find_up_to_0(self): self.assertEqual(list(primes(0)), [])
def test_find_up_to_ten(self): self.assertEqual(list(primes(10)), [2, 3, 5, 7])
from funcs import primes, get_abundant_numbers plist = primes( 10**5 ) abunds = get_abundant_numbers( 2, 30000, plist ) def sum_of_2_abunds( n ): a = 0 z = len(abunds) - 1 while a <= z: cand = abunds[a] + abunds[z] if cand == n: return (abunds[a],abunds[z]) elif cand < n: a += 1 else: z -= 1 return None tot = 0 for i in range(1, 28123): if sum_of_2_abunds(i) == None: tot += i print tot