python3随笔-求素数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010255642/article/details/82630251
import time
import math
start=time.perf_counter()
print("2")
for n in range(3,101):
    for i in range(2,int(math.sqrt(n))+1):
        if  (n%i==0):
            print("{2}不是素数:{0} * {1} = {2}".format(int(n/i),i,n))
            break
    else:
        print("{0}是素数".format(n))
print("程序运行时间:{0}秒".format(time.perf_counter()-start))      
    
    
...
83是素数
84不是素数:42 * 2 = 84
85不是素数:17 * 5 = 85
86不是素数:43 * 2 = 86
87不是素数:29 * 3 = 87
88不是素数:44 * 2 = 88
89是素数
90不是素数:45 * 2 = 90
91不是素数:13 * 7 = 91
92不是素数:46 * 2 = 92
93不是素数:31 * 3 = 93
94不是素数:47 * 2 = 94
95不是素数:19 * 5 = 95
96不是素数:48 * 2 = 96
97是素数
98不是素数:49 * 2 = 98
99不是素数:33 * 3 = 99
100不是素数:50 * 2 = 100
程序运行时间:5.13720264秒

猜你喜欢

转载自blog.csdn.net/u010255642/article/details/82630251