Code behorend bij Priemracen

#Programma horende bij de tekst "Priemracen"
import sympy
import time

team1 = 0
teamk = 0
maxT1 = 0
maxTk = 0
N = 2000000
p = 2
Eq = []
T1 = []
K = 4
t0 = time.process_time()
for j in range(N):
    p = sympy.nextprime(p)
    if p % K == 1:
        team1 += 1
    else:
        teamk += 1
    if team1 == teamk:
        Eq.append(p)
    if team1 > teamk:
        T1.append(p)
        if maxT1 < team1 - teamk:
            maxT1 = team1 - teamk
    else:
        if maxTk < teamk - team1:
            maxTk = teamk - team1
t1 = time.process_time()
print("Gelijk spel:", len(Eq))
print("Maximale winst Team 1:", maxT1)
print("Maximale winst Team ", K-1, ":", maxTk)
print("Team1 wint: ", len(T1))
print("priem", N, p)
print("Tijd:", t1-t0)
print("Ready")
#print(T1)

 

T1 = []
N = 50
p = 2
for j in range(N):
    p = sympy.nextprime(p)
    if p % 4 == 1:
        T1.append(p)
lt1 = len(T1)
plt1 = 2^lt1
print(lt1, T1)

 

for n in range(plt1):
    k = n
    cnt = 0
    P = 1
    while k > 0:
        if k % 2 == 1:
            P *= T1[cnt]
        k = k // 2
        cnt += 1
    M = P * P + 4
    MP = sympy.factorint(M)
    for mp in MP:
        if mp % 4 == 3:
            print ("mp", mp)
            print(n, P, MP)
print("Ready")

 

def maak_priemrij(n):
    # Deze functie genereert alle priemgetallen kleiner of gelijk aan n
    if n < 2:
        return []
    rij= list(range(2, n+1))
    priemrij = []
    pr = 1
    while pr <= n**(1/2):
        pr = rij.pop(0)
        priemrij.insert(len(priemrij), pr)
        rij = list(x for x in rij if (x % pr != 0))   
    return(priemrij + rij)

G = 1000000
priemrij = maak_priemrij(G)
priemrij1 = list(x for x in priemrij if (x % 4 == 1))
priemrij3 = list(x for x in priemrij if (x % 4 == 3))

 

def alb(rij, n):
    return(len(list(x for x in rij if (x <= n))))

rij = [1,3,4,5,6]
alb(rij, 6)

 

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = (15, 9)

def maak_plot(priemrij1, priemrij3, N):
    x = list(range(0, N))
    y1 = list(range(0, N))
    y3 = list(range(0, N))
    for j in range(0, N):
        y1[j] = alb(priemrij1, j)
        y3[j] = alb(priemrij3, j)
    plt.plot(x, y1, label=' van de vorm $4n+1$')
    plt.plot(x, y3, label=' van de vorm $4n+3$')
    plt.title('Aantal priemgetallen kleiner of gelijk aan $x$')
    plt.legend()
    plt.show()
    return

N = 100
maak_plot(priemrij1, priemrij3, N)

 

# Programma 5b: Dirichlet deel 2
N = 1000
maak_plot(priemrij1, priemrij3, N)

 

N = 100000
x = list(range(0, N))
y1 = list(range(0, N))
y3 = list(range(0, N))
y = list(range(0, N))
for j in range(0, N):
    y1[j] = alb(priemrij1, j)
    y3[j] = alb(priemrij3, j)
    y[j] = y3[j] - y1[j]
plt.plot(x, y, label='aantal van de vorm $4n+3$ - aantal de vorm $4n+1$')
plt.title('Verschil in aantal kleiner dan $x$')
plt.legend()
plt.show()