ข้ามไปยังเนื้อหา

ตะแกรงเอราโตสเตนีส

กรอง eratosthenes

นักคณิตศาสตร์กรีก eratosthenes หาเลขต้นแบบโดยไม่ทำการหาร: เขียนตัวเลขลง แล้วขีดฆ่าตัวคูณของแต่ละเลขต้นแบบ

[True] * (n + 1) สร้างรายการของ n + 1 True values, One for each number from 0 to n. Mark 0 and 1 as not prime. Then, for each p still marked True, set every multiple of p from p * p onwards to False. The numbers still marked True at the end are the primes.

เข้าสู่ระบบหรือสร้างบัญชี

IGCSE, A-Level & AP