Count primes below n · n未満の素数を数える
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
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を割り切れば、それは素数ではありません。
Complete countPrimes(int n) returning how many prime numbers are strictly less than n. Example: countPrimes(10) is 4 (2, 3, 5, 7). · countPrimes(int n) を完成させて、n より()(小さい素数の数を返してください。例: countPrimes(10) は 4 (2, 3, 5, 7)。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。