您的位置:首页 > 编程语言 > Go语言

Algorithms

2015-06-11 03:33 411 查看
Count prime numbers not exceeding n(n>0)

Pseudocode:
Input: an integer n > 1

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:
if A[i] is true:
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n :
A[j] := false

Output: all i such that A[i] is true.


The Sieve of Eratosthenes uses an extra O(n) memory and its runtime complexity is O(n log log n).

d

d

d

d

d

d

d

d

d
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: