Max-Russo's picture
Update backend.py
21ca53d verified
import gmpy2
import time
def fraction_function(x):
"""Calcola f(x) = 5*(1 + 1/x) + 1, equivalente a (6*x+5)/x"""
return gmpy2.mpq(6 * x + 5, x)
def calculate_x(n):
"""Calcola x = 25 + 5 * n * (n + 1)"""
return 25 + 5 * n * (n + 1)
def test_optimized_sequence(k_start, num_iterations):
"""
Itera per k da k_start a k_start + num_iterations - 1, impostando n = k,
e calcola il corrispondente x e f(x).
Restituisce una lista di tuple:
(k, n, x, N, d, is_N_prime, is_d_prime)
"""
results = []
total_primes = 0 # Contatore del totale dei numeri primi (N e d)
for k in range(k_start, k_start + num_iterations):
n = 3 + 21*k # n = Modulo 7
x = calculate_x(n)
frac = fraction_function(x)
N = frac.numerator
d = frac.denominator
is_N_prime = gmpy2.is_prime(N)
is_d_prime = gmpy2.is_prime(d)
if is_N_prime:
total_primes += 1
if is_d_prime:
total_primes += 1
results.append((k, n, x, N, d, is_N_prime, is_d_prime))
return results, total_primes