ツール ガイド
math 無料 サインアップ不要

素数チェッカー

10¹²までの任意の数が素数かどうかを確認し、素因数分解を表示して関連する素数の情報を探索します。

ツールを読み込み中…

このツールについて

1兆までの任意の整数を入力すると、それが素数かどうかを即座に確認できます。大きな数にはミラー-ラビン素数判定テストを使用します。合成数の素因数分解を表示し、次の素数と前の素数を検索し、特別な素数(メルセンヌ素数、双子素数、安全素数)を識別し、最初のN個の素数を生成することもできます。

使い方

  1. 1 数値フィールドに正の整数を入力してください。
  2. 2 「確認」をクリックして素数判定と素因数分解を確認してください。
  3. 3 「次の素数」と「前の素数」を使用して素数列をナビゲートしてください。
  4. 4 カウントを設定して「素数を生成」をクリックすると、最初のN個の素数がリスト表示されます。

What makes a number prime

A prime number is a whole number greater than 1 whose only divisors are 1 and itself. 7 is prime because nothing between 2 and 6 divides it evenly; 9 is not, because 3 × 3 = 9. Primes are the atoms of arithmetic: every integer above 1 is either prime or a unique product of primes, a result so fundamental it is called the Fundamental Theorem of Arithmetic. That uniqueness is why this tool, when a number is not prime, shows its full prime factorization — the one and only way to break it into prime building blocks.

How the tool tests primality so fast

The obvious way to check a number is trial division — try dividing by every integer up to its square root. That is fine for small numbers but crawls for large ones. This tool instead uses the Miller–Rabin primality test with a fixed set of "witnesses." Miller–Rabin reframes the question: it picks a base a and checks an algebraic identity that every prime must satisfy. If the number fails the identity for any witness, it is definitely composite. If it passes for the right set of witnesses, it is guaranteed prime below a known limit.

Crucially, the implementation uses a deterministic set of witnesses — the small primes 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41 — which are mathematically proven to give a correct answer for every number this tool accepts (up to 10¹²). The arithmetic is done with JavaScript BigInt so that the intermediate squarings never overflow. The result is an exact yes/no, not a probabilistic guess, computed almost instantly even for twelve-digit inputs.

A worked example

Enter 561. It looks like it might be prime — it is odd and not obviously divisible by small numbers. Trial division finds 561 = 3 × 11 × 17, so the tool reports it composite and shows that factorization. (561 is famous as the smallest Carmichael number, a composite that fools the simplest primality tests — but not Miller–Rabin with these witnesses.) Now enter 8191. It passes every witness, so the tool reports PRIME, and because 8191 = 2¹³ − 1 it also flags it as a Mersenne prime.

The special-prime badges

When a number is prime, the tool surfaces some of the structure mathematicians find interesting:

BadgeMeaningExample
Mersenne primeOne less than a power of two, 2ᵏ − 1, where k is itself prime31 = 2⁵ − 1
Twin primeDiffers by 2 from another prime(11, 13)
Safe prime(p − 1)/2 is also prime23, since 11 is prime

These are not trivia for their own sake. Mersenne primes drive the search for the largest known primes; twin primes sit at the heart of a famous unsolved conjecture; and safe primes are deliberately chosen in cryptography because their structure resists certain attacks on Diffie–Hellman key exchange.

Reading the factorization

For composite numbers the tool computes the prime factorization by trial division up to the square root, collecting repeated factors into exponents. So 360 is shown as 360 = 2³ × 3² × 5 rather than the longer 2 × 2 × 2 × 3 × 3 × 5. The exponent form is the compact, canonical way to write a factorization and the form you need for finding divisor counts, greatest common divisors, or least common multiples.

Why primes matter in the real world

  • Public-key cryptography. RSA encryption relies on the fact that multiplying two large primes is easy but factoring the product back is, with current methods, infeasible. The security of much of the web rests on that asymmetry.
  • Hashing and data structures. Hash tables often use a prime number of buckets to spread keys evenly and avoid clustering.
  • Pseudo-random generators. Many random-number algorithms use prime moduli to maximise their cycle length.
  • Error-correcting codes. Several coding schemes are built over fields whose size is prime.

Tips and common misconceptions

  • 1 is not prime. By definition a prime has exactly two distinct divisors; 1 has only one, so it is excluded. The tool requires inputs of at least 1 and treats 1 as non-prime.
  • 2 is the only even prime. Every other even number is divisible by 2, so primality "thins out" to odd candidates above 2.
  • Primes never stop. Euclid proved over two thousand years ago that there are infinitely many — the "Generate first N primes" panel just lists them in order, starting from 2.
  • Ending in 5 or an even digit means composite. Except for 2 and 5 themselves, any number ending in 0, 2, 4, 5, 6, or 8 is divisible by 2 or 5 and cannot be prime — a quick sanity check before you even type.

Everything runs in your browser; numbers you test are never sent anywhere.

よくある質問

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}