|
|
@ -1,19 +0,0 @@ |
|
|
|
from math import sqrt |
|
|
|
def isPrime(n): |
|
|
|
m=int(sqrt(n)) |
|
|
|
for i in range(2,m+1): |
|
|
|
if n%i ==0: |
|
|
|
return False |
|
|
|
return True |
|
|
|
def countPrimes(start,end): |
|
|
|
cnt=0 |
|
|
|
for i in range(start,end+1): |
|
|
|
if(isPrime(i)): |
|
|
|
cnt+=1; |
|
|
|
|
|
|
|
return cnt |
|
|
|
|
|
|
|
#主程序 |
|
|
|
for start in range(1,1000,100): |
|
|
|
print("%3d-%4d 有%d个素数"%\ |
|
|
|
(start,start+99,countPrimes(start,start+99))) |