跳到主要内容

资源 · 指南或文章

Primality Test

关于素数、合数以及素性测试回答什么问题的定义页,适合在编写 isPrime 函数之前需要掌握这些术语的人。

审核日期

打开原站: Primality Test (在新标签页中打开原网站)

添加到路线图

把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。

来源内容语言:英语

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 × 3) that are both smaller than 6. A primality test is an algorithm for determining whether an input number is prime. Among other fields of mathematics, it is used for cryptography. Unlike integer factorization, primality tests do not generally give prime factors, only stating whether the input number is prime or not. Factorization is thought to be a computationally difficult problem, whereas primality testing is comparatively easy (its running time is polynomial in the size of the input).

PrepKit 概览

本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。

适合人群
来源未说明适用级别
形式
参考资料

涵盖内容

  • 素数和合数的定义,以 5 和 6 为例。
  • 素性测试与整数分解有何不同,并指出素性测试可以在多项式时间内完成。

使用建议

这是 PrepKit 的学习建议,并非来源的说法。

写一个试除法的 isPrime,并大声解释为什么只需检查到平方根为止的因数。这个上界来自其他资料,而不是本 README。

范围与局限

非常单薄:没有点名任何测试方法,没有针对具体方法的代码讲解或复杂度,只依赖两个维基百科链接。

获取方式与形式

GitHub 上 trekhleb/javascript-algorithms(MIT)中的英文 README;免费阅读。

PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88

本概览的依据
  • src/algorithms/math/primality-test/README.md

收录此条目的页面

订阅 PrepKit 通讯

可选。使用 PrepKit 并不需要订阅。

我们如何处理你的邮箱