{
  "id": "semiprime",
  "title": "Semiprime",
  "lang": "en",
  "source_lang": "en",
  "summary": "A semiprime is a positive integer that is the product of exactly two primes, which may be equal.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Almost prime of order two",
    "2-almost prime"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/semiprime/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/semiprime/",
      "json": "https://aiwiki.page/zh/semiprime.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A semiprime is a positive integer that is the product of exactly two prime numbers, counted with multiplicity. Thus \\(n\\) is semiprime if \\(n=pq\\), where \\(p\\) and \\(q\\) are primes and may be equal. Semiprimes are studied in number theory and are important in cryptography, where products of two large primes provide the moduli used in systems such as RSA."
    },
    {
      "heading": "Definition and examples",
      "text": "The semiprimes, in increasing order, begin\n\n\\[4,\\ 6,\\ 9,\\ 10,\\ 14,\\ 15,\\ 21,\\ 22,\\ 25,\\ 26,\\ 33,\\ 34,\\ 35,\\ 38,\\ 39,\\ 46,\\ 49,\\ 51,\\ 55,\\ 57,\\ 58,\\ 62,\\ 65,\\ 69,\\ldots\\]\n\nFor example:\n\n- \\(4=2^2\\) and \\(49=7^2\\) are semiprimes because a repeated prime factor counts twice.\n- \\(6=2\\cdot3\\) and \\(35=5\\cdot7\\) are semiprimes with two distinct prime factors.\n- \\(12=2^2\\cdot3\\) is not semiprime: it has three prime factors when multiplicity is counted.\n- Neither \\(1\\) nor any prime number is semiprime.\n\nThe fundamental theorem of arithmetic ensures that this definition is unambiguous. If\n\n\\[n=p_1^{a_1}p_2^{a_2}\\cdots p_r^{a_r}\\]\n\nis the prime factorization of \\(n>1\\), define\n\n\\[\\Omega(n)=a_1+a_2+\\cdots+a_r.\\]\n\nThen \\(n\\) is semiprime exactly when \\(\\Omega(n)=2\\).\n\nSemiprimes are therefore the special case \\(k=2\\) of almost primes, integers having exactly \\(k\\) prime factors counted with multiplicity. Some sieve-theoretic terminology instead concerns integers with at most \\(k\\) prime factors, so the convention must be checked in that context."
    },
    {
      "heading": "Types and elementary properties",
      "text": "There are two types of semiprime:\n\nType | Form | Example | Number of positive divisors\nPrime square | \\(p^2\\) | \\(25=5^2\\) | 3\nProduct of distinct primes | \\(pq\\), \\(p\\ne q\\) | \\(35=5\\cdot7\\) | 4\n\nA semiprime with distinct prime factors is a square-free integer. Its positive divisors are precisely \\(1,p,q,pq\\). A prime square instead has the divisors \\(1,p,p^2\\).\n\nHaving four positive divisors does not by itself characterize semiprimes: \\(p^3\\) also has exactly four divisors, but has three prime factors counted with multiplicity.\n\nThe only even semiprimes are numbers of the form \\(2p\\), where \\(p\\) is prime. Every odd semiprime is the product of two odd primes. There are infinitely many semiprimes, since there are infinitely many primes and each prime \\(p\\) produces a distinct semiprime \\(2p\\).\n\nFor Euler’s totient function, which counts the positive integers at most \\(n\\) that are coprime to \\(n\\),\n\n\\[\\varphi(pq)=(p-1)(q-1)\\qquad(p\\ne q),\\]\n\nwhereas\n\n\\[\\varphi(p^2)=p(p-1).\\]\n\nThe distinction is essential: the formula for two distinct prime factors does not apply to a prime square."
    },
    {
      "heading": "Counting and distribution",
      "text": "Let \\(S(x)\\) denote the number of semiprimes not exceeding \\(x\\), and let \\(\\pi(x)\\) denote the number of primes not exceeding \\(x\\). Write \\(p_i\\) for the \\(i\\)-th prime. An exact counting formula is\n\n\\[S(x)= \\sum_{i=1}^{\\pi(\\sqrt{x})} \\left[ \\pi\\!\\left(\\frac{x}{p_i}\\right)-i+1 \\right].\\]\n\nTo obtain this formula, write each semiprime uniquely as \\(p_i p_j\\) with \\(i\\le j\\). Its smaller prime factor is at most \\(\\sqrt{x}\\); for a fixed \\(p_i\\), the permitted larger factors satisfy\n\n\\[p_i\\le p_j\\le \\frac{x}{p_i}.\\]\n\nThe summand counts these choices, including \\(p_j=p_i\\).\n\nA classical asymptotic result, the \\(k=2\\) case of Landau’s theorem on almost primes, states that\n\n\\[S(x)\\sim\\frac{x\\log\\log x}{\\log x} \\qquad(x\\to\\infty),\\]\n\nwhere \\(\\log\\) is the natural logarithm and \\(\\sim\\) means that the ratio of the two sides tends to \\(1\\).\n\nConsequently, semiprimes have natural density zero:\n\n\\[\\lim_{x\\to\\infty}\\frac{S(x)}{x}=0.\\]\n\nNevertheless, comparison with the prime number theorem gives\n\n\\[\\frac{S(x)}{\\pi(x)}\\sim\\log\\log x.\\]\n\nThus the cumulative number of semiprimes eventually exceeds the number of primes by an unbounded factor.\n\nPrime squares contribute only \\(\\pi(\\sqrt{x})\\) to \\(S(x)\\), a negligible proportion asymptotically. Almost all semiprimes, in this counting sense, have distinct prime factors."
    },
    {
      "heading": "Recognition and factorization",
      "text": "Given a complete prime factorization of an integer, determining whether it is semiprime is immediate: the sum of the prime-factor exponents must equal two. Conversely, a proposed factorization \\(n=pq\\) certifies semiprimality once both factors have passed a primality test.\n\nA straightforward recognition method tries possible prime divisors up to \\(\\sqrt n\\). If the smallest prime divisor is \\(p\\), then \\(n\\) is semiprime exactly when \\(n/p\\) is prime. This method is practical for small integers but inefficient for large inputs measured by their number of digits.\n\nIn integer factorization, large semiprimes whose factors have comparable sizes are particularly important. A semiprime with a small factor can often be factored quickly; the definition of semiprimality alone therefore implies no particular level of computational difficulty."
    },
    {
      "heading": "Role in cryptography",
      "text": "In the standard two-prime RSA cryptosystem, the public modulus is\n\n\\[n=pq,\\]\n\nwhere \\(p\\) and \\(q\\) are distinct large primes. The factors are kept secret, while encryption and signature operations use modular arithmetic modulo \\(n\\).\n\nKnowing \\(p\\) and \\(q\\) allows computation of \\(\\varphi(n)\\), and hence recovery of the private exponent from the public exponent under the usual RSA conditions. For a distinct-prime semiprime, knowing \\(\\varphi(n)\\) also reveals the factors, because\n\n\\[p+q=n-\\varphi(n)+1.\\]\n\nThe primes are then the roots of the quadratic equation\n\n\\[t^2-\\bigl(n-\\varphi(n)+1\\bigr)t+n=0.\\]\n\nFactoring the modulus therefore breaks standard RSA. However, the general problem of inverting RSA has not been proved equivalent to factoring. Security also depends on key generation, padding, and implementation, rather than on semiprimality alone."
    }
  ],
  "links": [
    "integer",
    "prime-number",
    "number-theory",
    "fundamental-theorem-of-arithmetic",
    "eulers-totient-function",
    "natural-logarithm",
    "prime-number-theorem",
    "primality-test",
    "rsa-cryptosystem",
    "modular-arithmetic",
    "quadratic-equation"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}