【发布时间】:2020-12-02 09:56:32
【问题描述】:
谁能帮我制作 Eratosthenes 算法的循环不变量?
这里是和平的代码:
埃拉托色尼算法筛是 输入:一个整数 n > 1。 输出:从 2 到 n 的所有素数。
let A be an array of Boolean values, indexed by integers 2 to n,
initially all set to true.
for i = 2, 3, 4, ..., not exceeding √n do
if A[i] is true
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do
A[j] := false
return all i such that A[i] is true.
【问题讨论】:
标签: algorithm sieve-of-eratosthenes loop-invariant