愚蠢的求素数
import math
import time
def BySqrt(a,b):
numList = list()
flag = 0
for i in range(a,b):
for j in range(2, int(math.sqrt(i)) + 1):
if i % j == 0:
flag = 1
break
else:
flag = 0
if flag == 0:
numList.append(i)
return numList
for num in BySqrt(1,100):
print num
start = time.clock()
end = time.clock()
print end-start
求和
def AddUp(a,b):
s = 0
for i in range(a,b):
s=s+i
return s
print AddUp(1,100)
网友评论