求质数(多个方法)

lk=[]
for i in range(2,100):
    fg=0
    for n in range(2,i):
        if i%n==0:
            fg=1
    while(fg==0):
        lk.append(i)
        break
    
print(lk)

/*******************************************************************************************************************************************/

lk=[]
for i in range(2,101):
    fg=0
    for n in range(2,i):
        if i%n==0:
            fg=1
    while(fg==0):
        lk.append(i)
        break
print(lk)  

/*******************************************************************************************************************************************/

import math
lk=[2,3]
for i in range(2,101):
    t=math.ceil(i/2+0.000005)
    for n in range(2,t):
        if i%n==0:
            break
        elif(n==t-1):
            lk.append(i)
print(lk)

/*******************************************************************************************************************************************/

num=[]
for i in range(2,10000):
    for n in range(2,i):
        if(i%n==0):
            break
    else:
        num.append(i)
print(num)
print(len(num))

/*******************************************************************************************************************************************/

import math
lk=[]
m=int(input())
n=int(input())                          
fg=0
if m==2 :
    lk=[2,3]
    fg=1
elif m==3:
    lk=[3]
    fg=2
if fg==0:
    if m%2==0:
        m=m+1
elif fg==1 or fg==2:
    m=5  
for i in range(m,n,2):    
    if i%5==0 or i%3==0:
        continue
    else:
        q=int(math.sqrt(i))
        for j in range(2,q+1):
            if i%j==0:
                break
            elif j==q:
                 lk.append(i)
if m<=5:
    lk.append(5)

print(lk) 

/*******************************************************************************************************************************************/

import math
num=[]
for i in range(2,101):
    fg = 0
    k=math.ceil(i/2+0.001)
    for j in range(2,k):
        if i % j == 0:
            fg = 1
    if fg == 0:
        num.append(i)
print (num)

/*******************************************************************************************************************************************/
import math
index = 50
num = [2,3]
num1 = [2]

for i in range(2,index):
    y=math.sqrt(i)+0.00004
    k=math.ceil(y)
    for j in range(2,k):       
        if(i%j==0):
            break
        elif(j==k-1):
            #print(i,"是质数")
            num.append(i)
print(num) 
            
         
for i in range(2,index):
    for j in range(2,i):
        if(i%j==0):
            break
        if(j==i-1):
            num1.append(i)
print(num1)

你可能感兴趣的:(学习笔记)