python <素数>
来源:互联网 发布:免费财务分析软件 编辑:程序博客网 时间:2024/05/29 16:54
import math
import gc
class calculator:
def __init__(self):
pass
# 素数计算
def pnum_2(self,n):
m = []
gc.disable()
for x in xrange(2,n):
flag = 0
for y in xrange(2,int(math.sqrt(x))+1):
if x%y ==0:
flag = 1
if flag == 0:
m.append(x)
gc.enable()
print m,'\nthe prime number total: %d' %len(m)
if __name__ == '__main__':
cal = calculator()
cal.pnum_2(1000)
import gc
class calculator:
def __init__(self):
pass
# 素数计算
def pnum_2(self,n):
m = []
gc.disable()
for x in xrange(2,n):
flag = 0
for y in xrange(2,int(math.sqrt(x))+1):
if x%y ==0:
flag = 1
if flag == 0:
m.append(x)
gc.enable()
print m,'\nthe prime number total: %d' %len(m)
if __name__ == '__main__':
cal = calculator()
cal.pnum_2(1000)
0 0
- python 素数
- python <素数>
- python 素数
- Python素数筛选法
- Python - 素数筛
- python学习日记-素数
- python求素数
- 求素数 -- Python实现
- 素数的实现--python
- 埃氏筛法求素数-Python
- Python求素数算法
- 循环素数求解 python
- python--素数 最大公约数
- 线性筛选素数--python
- 显示素数 python
- python求素数时间
- 筛法求素数--python实现
- python求素数
- qt4.8.6-vtk5.10-vs2010整合
- python os模块与input操作
- The import org.cocos2dx.lib cannot be resolved
- Linux测试网卡绑定
- shell $代表意义
- python <素数>
- eclipse删除所有注释
- unity遮罩_2(对罩子做处理)
- 如何在Linux中使用awk命令
- [Unity3D]UI方案及制作细节(NGUI/EZGUI/原生UI系统)
- 【数据结构】单链表(二)单链表的逆置,合并与删除
- python中的_doc_是什么
- Quick-cocos2d-x-3.2中示例Coinfilp解析(二)
- C++面试宝典