ultraji
发表于 2018-2-20 08:53:46
import math
def isPrime(x):
for i in range(2,int(math.sqrt(x)+1)):
if(x%i == 0):
return False
return True
for i in range(101,201):
if isPrime(i):
print(i,end=' ')
nforev
发表于 2018-2-23 15:50:45
import math as m
mul = 1
count = 0
for n in range(101,201):
for i in range(2,int(m.sqrt(n))):
mul *= n % i
if mul:
print(n)
count += 1
mul = 1
print("count == %s"%str(count))
纳兰小寒
发表于 2018-2-25 16:38:45
for x in range(101,200):
a = int(x ** 0.5)
flag = True
if x % 2 == 0:
continue
for y in range(2,a+1):
if x % y == 0:
flag = False
break
if flag:
print(x)
victor.xu
发表于 2018-2-25 16:44:34
def is_prime_num(m,n):
lis = []
#m为奇数,遍历定义域内奇数
for i in range(m, n+1, 2):
k = 2
count = 0
j = int(i ** 0.5)
while k <= j:
if i % k == 0:
k += 1
count += 1
else:
k += 1
if count == 0:
lis.append(i)
return lis
result = is_prime_num(101,200)
print(result)
lchelement
发表于 2018-2-26 11:10:38
'''
题目:判断101-200之间有多少个素数,并输出所有素数。
程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 '''
list1=[]
list2=[]
count=0
for i in range(101,201):
for j in range(2,int(i**0.5)+1):
if i % j == 0:
list1.append(i)
for k in range(101,201):
list2.append(k)
for a in list2:
if a not in list1:
print(a,end=' ')
count += 1
print('共有%d个素数'%count)
昵称加载错误
发表于 2018-2-26 12:12:38
m = 0
q = 0
for p in range(101,201):
for i in range(1,p+1):
if p%i == 0:
m += 1
if m == 2:
print(p)
q = q+1
m = 0
print('有',q,'个质数')
瞬秒爆加速
发表于 2018-3-5 13:55:43
本帖最后由 瞬秒爆加速 于 2018-3-5 13:58 编辑
print()
for i in range(101,200):
if all(i%ii for ii in range(2,int(i**0.5)+1)):
print(i)
benzhj
发表于 2018-3-8 12:37:35
from math import sqrt
l = []
temp = 0
for i in range(101, 201):
temp = int(sqrt(i) + 0.5)
#print (temp)
pd = 0
for x in range(2, temp+1):
if i % x == 0:
pd = 1
break
if pd != 1:
l.append(i)
print(l)
tusumili
发表于 2018-3-11 21:15:53
本帖最后由 tusumili 于 2018-3-11 21:30 编辑
i = 0
for x in range(101,201):
a = x % 2
b = x % 3
c = x % 5
d = x % 7
e = x % 11
f = x % 13
g = x % 17
if a != 0 and b != 0 and c != 0 and d != 0 and e != 0 and f != 0 and g != 0:
print(x)
i += 1
print('101到200之间一共有' + str(i) + '个质数')
zxw920506
发表于 2018-3-22 10:07:38
sum = 0
for x in range(101, 201):
a = 0
for y in range(2,x):
if x % y == 0:
a += 1
break
if a == 0:
print(x,end=' ')
sum += 1
print('一共%d个素数'% sum)
诸葛靓仔
发表于 2018-3-22 21:38:55
import math
num=0
for i in range(101,201):
for j in range(2,int(math.sqrt(i))+1):
if i % j ==0:
break
elif i%j!=0:
if j == (int(math.sqrt(i))):
print("i=",i,' ')
num+=1
print(num)
tsembrace
发表于 2018-4-7 11:51:04
#判断101-200之间有多少个素数,并输出所有素数
import math
def isPrime(n):
x=int(math.sqrt(n))
for i in range(2,x+1):
if n%i==0:
return False
return True
primelist101_200=list(filter(isPrime,))
print('101~200之间共有%d个素数.'% len(primelist101_200))
print(primelist101_200)
天天学习$
发表于 2018-4-23 19:38:12
def prime_number():
list0 = []
for i in range(101,201):
list1 = []
for j in range(1,(i + 1)):
if i % j == 0:
list1.append(j)
if len(list1) == 2:
list0.append(i)
print('101到200之间有%d个素数' %(len(list0)),'分别是:' ,list0)
编程学学学
发表于 2018-5-3 23:36:30
count=0
for i in range(101,201):
for j in range(2,i+1):
if i%j == 0 and j!=i:
break
if i%j==0 and j==i:
print(i)
count = count+1
print("共有%s个素数"%count)
萧丹夜
发表于 2018-5-8 20:56:27
import math
i = 2
j = 0
for k in range(101,201):
while i <= math.sqrt(k)+1:
if k % i == 0:
break
else:
i += 1
if k % i != 0:
print(k,end=' ')
j += 1
i = 2
print('素数个数为:',j)
张大哈
发表于 2018-6-14 09:54:32
import math
for i in range(100,201):
for j in range(2,int(math.sqrt(i))+1):
if i%j==0:
break
else:
print(i)
Milo_Ye
发表于 2018-7-18 11:33:43
import math
list1 = list()
s = 0
for i in range(101, 201):
for j in range(2, int(math.sqrt(i))+1):
if i%j != 0:
s = 1
else:
s = -1
break
if s==1:
list1.append(i)
n = len(list1)
print("共有%s个素数" % n)
for each in list1:
print(each, end = '')
892427369
发表于 2018-7-18 21:37:17
t = 0
for a in range(101,201):
for b in range(2,a):
if a % b == 0:
t += 1
if t == 0:
print(a,end=" ")
t = 0
孤独的程序
发表于 2018-7-29 21:30:08
list0 = list(range(101, 201))
list1 = list0[:]#复制新列表,对新列表进行删除元素的操作,不能对原列表直接进行删除元素操作
for i in list0:
for j in range(2,int(i**0.5)+1):
if i % j == 0:
list1.remove(i)
break
print('101~200之间的素数一共有:%d个,分别是:\n' % len(list1), list1)
quan-renda
发表于 2018-8-15 17:01:50
import math
list1=[]
list2=[]
for i in range(101,201):
for j in range(2,i):
c=math.fmod(i,j)
if int(c)==0:
list2.append(i)
break
if int(c)!=0:
list1.append(i)
print('素数有:',list1)
print('非素数有:',list2)