筛法求素数
2010-06-24 10:20
232 查看
石器时代的版本:
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
可以自己选择上限:
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
修改错误:
import math l=[] for i in xrange(2, 100000): if any(i%x==0 for x in l if x<=math.sqrt(i)): continue else: print i l.append(i) # for p in l: # print p print "amount :", len(l)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
可以自己选择上限:
import sys import math high = int(sys.argv[1]) if len(sys.argv)==2 else 10000 l=[] for i in xrange(2, 100000): if any(i%x==0 for x in l if x<=math.sqrt(i)): continue else: print i l.append(i) for p in l: print p print "amount:", len(l)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
修改错误:
import sys import math high = int(sys.argv[1]) if len(sys.argv)==2 else 10000 l=[] for i in xrange(2, 100000): if any(i%x==0 for x in l if x<=math.sqrt(i)): continue else: print i l.append(i) print "amount:", len(l)
![](http://blog.csdn.net/ccat/article/details/chrome:/itsalltext/locale/gumdrop.png)
相关文章推荐
- wikioi 2849 素数判定 3 (筛法求质)
- 数组之用筛法求N之内的素数
- 素数密度——区间筛法(详解)
- 素数筛,单点的欧拉函数,筛法求欧拉函数
- 线性筛法(欧拉筛法)求素数
- 素数的一般筛法与线性筛法
- 用筛法求100之内的素数。
- 素数的区间筛法
- MOOC清华《程序设计基础》第4章第1题:找出ab间的素数(用筛法做)
- 筛法素数表
- 用筛法求之N内的素数。(N < 1000000)
- HDU 6069 Counting Divisors (素数+筛法)
- C语言中素数的快速判断和筛法创建。
- 筛法求100002(十万零二)个素数
- 用筛法求之N内的素数。
- Codeforces 432C Prime Swaps【筛法素数预处理+贪心】
- poj 2689 Prime Distance 筛法/二次筛法/区间素数
- 幸运数 幸运数是波兰数学家乌拉姆命名的。它采用与生成素数类似的“筛法”生成。
- 使用欧拉筛法求素数和
- 埃拉托斯尼斯筛法判别素数