#coding:utf-8 #设置python文件的编码为utf-8,这样就可以写入中文注释
def primeRange(n):
myArray=[1 for x in range(n+1)] ##列表解析,生成长度为(n+1)的列表,每个数值都为1
myArray[0]=0
myArray[1]=0
startPos=2
while startPos <= n:
if myArray[startPos]==1:
key=2
resultPos = startPos * key #可知startPos的整数倍都不是素数,设置startPos的整数倍的位置为0表示非素数
while resultPos <= n:
myArray[resultPos] =0
key += 1
resultPos = startPos *key
startPos += 1
resultList=[] ##将最终的素数保存在resultList列表返回
startPos=0
while startPos <= n:
if myArray[startPos] == 1:
resultList.append(startPos)
startPos += 1
return resultList
numString=raw_input("Input the Range(>3):")
numInt=int(numString)
if numInt <= 3:
print "The Number Need to be greater than 3"
else:
primeResult=primeRange(numInt)
print "The Result is:",primeResult
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有