Prime Checker & Factorizer
Check if a number is prime and find its prime factorization.
Primes up to
About this tool
A prime number is a natural number greater than one that has no positive divisors other than one and itself. Prime checking and factorization are fundamental operations in number theory, cryptography, and mathematics education. This tool determines whether a given number is prime and breaks it down into its prime factors, revealing the building blocks of any integer.
To use this tool, simply enter a positive integer and click the button to check or factorize. The tool instantly displays whether the number is prime, and if not, shows its complete prime factorization as a product of primes. This is useful for mathematicians, students learning number theory, and anyone curious about the mathematical structure of numbers.
Prime factorization works by dividing a number by successive prime divisors until only one remains. For large numbers, this process can be computationally intensive, but this tool handles typical use cases instantly. Understanding prime factors helps in solving problems related to least common multiples, greatest common divisors, and cryptographic algorithms.
Frequently Asked Questions
Code Implementation
def prime_factors(n: int) -> dict[int, int]:
"""Return prime factorization as {prime: exponent} dict."""
if n < 2:
return {}
factors = {}
d = 2
while d * d <= n:
while n % d == 0:
factors[d] = factors.get(d, 0) + 1
n //= d
d += 1
if n > 1:
factors[n] = factors.get(n, 0) + 1
return factors
def format_factorization(n: int) -> str:
factors = prime_factors(n)
parts = [f"{p}^{e}" if e > 1 else str(p) for p, e in sorted(factors.items())]
return " Γ ".join(parts)
print(prime_factors(360)) # {2: 3, 3: 2, 5: 1}
print(format_factorization(360)) # 2^3 Γ 3^2 Γ 5
print(format_factorization(97)) # 97 (prime itself)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.