\( (n, t) \) Number Theory

Primality Tests

Brute Force Factorization

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

This function takes an integer n as input and returns a list of prime factors of n. It employs a brute-force approach by iteratively dividing n by increasing divisors starting from 2 until n becomes 1. This algorithm is not efficient and there are often better ways to find prime factors of a number.


Fermat Factorization

fermat_factorization(n: int) -> tuple[int, int]

Fermat's factorization algorithm is an integer factorization method that exploits the property of a difference of squares. Given an odd integer \( n \), it finds two factors \( p \) and \( q \) such that \( n = pq \). The algorithm works by searching for integers \( a \) and \( b \) such that \( a^2 - b^2 = n \), then \( n = (a + b)(a - b) \).