Ejemplo n.º 1
0
def test_prime_generator():
    prime_generator_limit_cases = [
        (60, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]),
        (1, [])
    ]
    prime_generator_count_cases = [
        (10, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]),
        (1, [2]),
        [0, []]
    ]
    for inp, output in prime_generator_limit_cases:
        assert list(prime_generator(limit=inp)) == output
    for inp, output in prime_generator_count_cases:
        assert list(prime_generator(count=inp)) == output
Ejemplo n.º 2
0
def compute():
    LIMIT = 10**8
    MOD = 1000000009
    ans = 1
    for p in eulerlib.prime_generator(LIMIT):
        power = count_factors(LIMIT, p)
        ans *= 1 + pow(p, power * 2, MOD)
        ans %= MOD
    return str(ans)
Ejemplo n.º 3
0
def compute():
    LIMIT = 10 ** 8
    MOD = 1000000009
    ans = 1
    for p in eulerlib.prime_generator(LIMIT):
        power = count_factors(LIMIT, p)
        ans *= 1 + pow(p, power * 2, MOD)
        ans %= MOD
    return str(ans)
Ejemplo n.º 4
0
def main():
    total = 100000000
    primes_set = set(tqdm(prime_generator(limit=total), total=total))
    s = 0
    for i in tqdm(primes_set):
        flag = True
        for d in proper_divisors(i - 1):
            if d + (i - 1) // d not in primes_set:
                flag = False
                break
        if flag:
            s += i - 1
    print(s)
Ejemplo n.º 5
0
def compute():
    # Note about the mathematical simplification:
    # (p-5)! + (p-4)! + (p-3)! + (p-2)! + (p-1)!
    # = (p-5)! * (1 + (p-4) + (p-4)(p-3) + (p-4)(p-3)(p-2) + (p-4)(p-3)(p-2)(p-1))
    # = (p-5)! * (1 + (-4) + (-4)(-3) + (-4)(-3)(-2) + (-4)(-3)(-2)(-1))
    # = (p-5)! * (1 + -4 + 12 + -24 + 24)
    # = (p-5)! * 9
    # = (p-1)! / ((p-1)(p-2)(p-3)(p-4)) * 9
    # = (p-1)! / ((-1)(-2)(-3)(-4)) * 9
    # = (p-1)! / 24 * 9
    # = (p-1)! * (3 * 3) / (3 * 8)
    # = (p-1)! * 3 / 8
    # = -1 * 3 / 8  (by Wilson's theorem)
    # = -3/8 mod p.
    # Every part of the equation is modulo a prime p > 4.
    def s(p):
        return (p - 3) * eulerlib.reciprocal_mod(8 % p, p) % p

    ans = sum(s(p) for p in eulerlib.prime_generator(10**8) if p >= 5)
    return str(ans)
Ejemplo n.º 6
0
def compute():
	# Note about the mathematical simplification:
	# (p-5)! + (p-4)! + (p-3)! + (p-2)! + (p-1)!
	# = (p-5)! * (1 + (p-4) + (p-4)(p-3) + (p-4)(p-3)(p-2) + (p-4)(p-3)(p-2)(p-1))
	# = (p-5)! * (1 + (-4) + (-4)(-3) + (-4)(-3)(-2) + (-4)(-3)(-2)(-1))
	# = (p-5)! * (1 + -4 + 12 + -24 + 24)
	# = (p-5)! * 9
	# = (p-1)! / ((p-1)(p-2)(p-3)(p-4)) * 9
	# = (p-1)! / ((-1)(-2)(-3)(-4)) * 9
	# = (p-1)! / 24 * 9
	# = (p-1)! * (3 * 3) / (3 * 8)
	# = (p-1)! * 3 / 8
	# = -1 * 3 / 8  (by Wilson's theorem)
	# = -3/8 mod p.
	# Every part of the equation is modulo a prime p > 4.
	def s(p):
		return (p - 3) * reciprocal_mod(8 % p, p) % p
	
	ans = sum(s(p) for p in eulerlib.prime_generator(10**8) if p >= 5)
	return str(ans)
Ejemplo n.º 7
0
import eulerlib
import math
import time
once = time.time()
pliste = eulerlib.prime_generator(10**8)
print(pliste(13))


def is_prime(a):
    if x <= 1:
        return False
    elif x <= 3:
        return True
    elif x % 2 == 0:
        return False
    else:
        for i in range(3, sqrt(x) + 1, 2):
            if x % i == 0:
                return False
        return True


def func(p):
    for i in range(1, p):
        if (8 * i + 3) % p == 0:
            return i


toplam = 0
for p in pliste:
    toplam = toplam + func(p)