Skip to content

Count primes below n · ⁨数小于 n 的质数⁩

English

Count primes below n

Return how many prime numbers are strictly less than n. A prime has no divisors other than 1 and itself. For each candidate k, test divisors only up to √k (i.e. while d * d <= k) — once one divides k evenly, it isn't prime.

中文

数小于 n 的质数

返回严格小于 n 的质数有多少个。质数除了 1 和它自身没有其他因数。对每个候选数 k,只需测试到 √k 为止的因数(即 d * d <= k)—— 一旦有一个能整除 k,它就不是质数。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩