You are viewing a single comment's thread. Return to all comments →
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) p = 2 while (p * p <= max_num): if (is_prime[p] == True): for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 prime_numbers = [p for p in range(2, max_num + 1) if is_prime[p]] return prime_numbers def count_twin_primes(L, R): primes = sieve_of_eratosthenes(R) primes_in_range = [p for p in primes if p >= L] twin_prime_count = 0 for i in range(len(primes_in_range) - 1): if primes_in_range[i + 1] - primes_in_range[i] == 2: twin_prime_count += 1 return twin_prime_count L, R = map(int, input().split()) result = count_twin_primes(L, R) print(result)
Seems like cookies are disabled on this browser, please enable them to open this website
Twins
You are viewing a single comment's thread. Return to all comments →