# Sieve of Eratosthenes[ZT]

1100人阅读 评论(0)

Eratosthenes also conceived the "Sieve of Eratosthenes ", a method of identifying prime numbers.

A prime number is a natural number greater than 1 that can be divided without remainder only by itself and by 1. Natural numbers n that can be divided by a number less than n and greater than 1 are composite numbers. The Sieve of Eratosthenes identifies all prime numbers up to a given number n as follows:

1. Write down the numbers 1, 2, 3, ..., n. We will eliminate composites by marking them. Initially all numbers are unmarked.
2. Mark the number 1 as special (it is neither prime nor composite).
3. Set k=1. Until k exceeds or equals the square root of n do this:
• Find the first number in the list greater than k that has not been identified as composite. (The very first number so found is 2.) Call it m. Mark the numbers
 2m, 3m, 4m, ...

as composite. (Thus in the first run we mark all even numbers greater than 2. In the second run we mark all multiples of 3 greater than 3.)
• m is a prime number. Put it on your list.
• Set k=m and repeat.

http://www.math.utah.edu/~alfeld/Eratosthenes.html

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：526625次
• 积分：7044
• 等级：
• 排名：第3785名
• 原创：173篇
• 转载：4篇
• 译文：2篇
• 评论：187条
评论排行
最新评论