Files
python/C++专题课程/质数相关/素数筛选法.txt
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

13 lines
644 B
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

筛选法
  显然以上的枚举法,不管如何改进都是不能AC的,所以枚举法肯定是行不通的。
  用筛法求素数的基本思想是:把从1开始的、某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉。剩下的数中选择最小的数是素数,然后去掉它的倍数。依次类推,直到筛子为空时结束。如有:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  1不是素数,去掉。剩下的数中2最小,是素数,去掉2的倍数,余下的数是:
  3 5 7 9 11 13 15 17 19 21 23 25 27 29
  剩下的数中3最小,是素数,去掉3的倍数,如此下去直到所有的数都被筛完,求出的素数为:
  2 3 5 7 11 13 17 19 23 29
判断一个数是不是质数(素数),3种方式介绍