\( (n, t) \) Number Theory

Generating Primes

Trial Division

trial_division(n: int) -> list[int]

The trial division function iterates over numbers from 2 to n, checking each number for primality using trial division. It divides each number by all integers up to its square root to determine if it is divisible by any other number besides 1 and itself. If the number is found to be prime, it is added to the list of primes.


Sieve of Eratosthenes

sieve_of_eratosthenes(n: int) -> list[int]

The Sieve of Eratosthenes function initializes a boolean array is_prime of size n + 1, where each element is initially set to True. It then iterates over the integers from 2 to the square root of n, marking multiples of each prime number as False in the is_prime array. Finally, it constructs a list of prime numbers based on the is_prime array and returns it.