码迷,mamicode.com
首页 > 编程语言 > 详细

Python实现求1-1000以内的素数

时间:2019-11-12 11:12:46      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:class   print   style   pytho   表示   col   def   python   nbsp   

def func():
    for i in range(2,1000):
        # count表示被整除的次数
        count = 0
        for j in range(1,i+1):
            if i%j==0:
                count+=1
            # count==2说明,该数字只能被1和它本身整除
            if count==2:
                if i==j:
                    print(i)


func()

 

Python实现求1-1000以内的素数

标签:class   print   style   pytho   表示   col   def   python   nbsp   

原文地址:https://www.cnblogs.com/lxmtx/p/11840130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!