Commit dd771dec authored by Taddeus Kroes's avatar Taddeus Kroes

herp

parent 9547fad4
#!/usr/bin/env python
from __future__ import division
from math import sqrt, ceil
from primes import is_prime, nprimes
def primes_until(n):
""" Sieve of Eratosthenes """
lst = [False] * n
i = 2
while i < n:
if not lst[i]:
yield i
for j in xrange(i, n, i):
lst[j] = True
i += 1
print list(nprimes(15499))
import sys; sys.exit()
def times(a, b):
return a * b
def div(m, n):
return not divmod(n, m)[1]
MAX = 2000000
all_primes = list(primes_until(MAX))
known_primes = {}
def primes(n):
for p in all_primes:
if p >= n:
raise StopIteration
for p in range(2, n):
if p in known_primes:
yield p
elif is_prime(p):
known_primes[p] = None
yield p
def phi(n):
return reduce(times, iter(1 - 1 / p for p in primes(n) if div(p, n)), n)
return reduce(times, iter(1 - 1 / p for p in primes(n) if not n % p), n)
def resilience(d):
return phi(d) / (d - 1)
d = 2
d = 30
while True:
print d,
try:
while resilience(d) >= 15499 / 94744:
d += 1
res = resilience(d)
if d == MAX:
print 'maximum reached:',
if res < 15499 / 94744:
break
except KeyboardInterrupt:
print 'interrupted:',
print d
print res, 15499 / 94744
d += 30
#!/usr/bin/env python
from math import gamma, factorial
def S(p):
return sum(factorial(p - k) for k in range(1, 6)) % p
def modfac(, p)
facs = [factorial(p) for p in range(5)]
total = s = S(5)
pmin6fac = 0
pmin1fac = factorial(5)
print 5, S(5)
N = 100
facs = [factorial(p) % p for p in range(5)]
for p in xrange(6, 1000000):
s = s - pmin6fac + pmin1fac
total += s % p
if s: print p, s % p
pmin6fac *= p - 5
pmin1fac *= p
print total
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment