Exemplo n.º 1
0
def generate_pq(min_val=PQ_MIN):
    p_times, q_times, max_times = None, None, 10
    p, q = None, None

    while p_times == q_times:
        p_times = randint(1, max_times)
        q_times = randint(1, max_times)

    prime_gen = prime.primes_above(min_val)

    for _ in range(p_times):
        p = next(prime_gen)

    for _ in range(q_times):
        q = next(prime_gen)

    return p, q
Exemplo n.º 2
0
import pyprimes as pp
import itertools as it

four_primes = []
for p in pp.primes_above(1000):
    if p >= 9999: break
    four_primes.append(p)
N = len(four_primes)

def prime_perms():
    for i in range(N):
        for j in range(i+1, N):
            a, b = four_primes[i], four_primes[j]
            c = 2*b - a
            if set(str(a)) == set(str(b)) == set(str(c)) and pp.isprime(c):
                print a, b, c

prime_perms()
Exemplo n.º 3
0
__author__ = 'JPate'

import random
import pyprimes
from datetime import datetime

startTime = datetime.now()
size = 20000
fileInt = open('20kBits_Int.txt', 'w')
fileList = open('20kBits_List.txt', 'w')
hugeint = []
num = pyprimes.primes_above(10**6)

for i in range(0, random.randint(0, 100)):
    p = next(num)
print(p)


found = 0
while found == 0:
    count = 0
    g = random.randint(1, p)
    for i in range(1, 2500):
        if g**i % p == 1:
            count += 1
            if count > 1:
                break
    if count == 1:
        found = 1
    else:
        print('g: ', g, ' FAIL      count:', count, 'TIME FROM BEGINING: ', datetime.now()-startTime)
Exemplo n.º 4
0
def test_fizzbuzz():
    prime = pyprimes.primes_above(5)
    assert FizzBuzz.fizzbuzz(i=next(prime) * 3) == 'fizz'
    assert FizzBuzz.fizzbuzz(i=next(prime) * 5) == 'buzz'
    assert FizzBuzz.fizzbuzz(i=next(prime) * 15) == 'fizzbuzz'
Exemplo n.º 5
0
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes."""

from pyprimes import isprime, primes_above


def truncates(n: int):
    mystr = str(n)
    mystrlen = len(mystr)
    for x in range(1, mystrlen):
        yield int(mystr[x:mystrlen])
        yield int(mystr[0:x])


truncatable_primes = set()

for root_prime in primes_above(7):
    complex_found = False
    for truncate in truncates(root_prime):
        if complex_found:
            break
        complex_found = not (isprime(truncate))

    if not (complex_found):
        print(root_prime)
        truncatable_primes.add(root_prime)
        if len(truncatable_primes) == 11:
            break

print()
print("Sum: ", sum(truncatable_primes))
Exemplo n.º 6
0
import pyprimes

M = [0 for _ in xrange(10)]
N = [0 for _ in xrange(10)]
S = [0 for _ in xrange(10)]

for p in pyprimes.primes_above(999999999):
    if p > 9999999999:
        break
    for d in xrange(10):
        n = str(d).count(str(d))
        if n > M[d]:
            M[d] = n
            N[d] = 1
            S[d] = p
        elif n == M[d]:
            M[d] = n
            N[d] += 1
            S[d] += p

print sum(S)
Exemplo n.º 7
0
import pyprimes

phi = (1 + 5 ** 0.5) / 2
psi = -1 / phi
count = 0
somme = 0
for a in pyprimes.primes_above(10**14):
    count += 1
    f = int(1 / 5 ** 0.5 * (phi ** a - psi ** a))
    somme += f
    somme %= 1234567891011
    if count == 100000:
        break
print somme