a121: 質數又來囉
http://zerojudge.tw/ShowProblem?problemid=a121
- MAX=10000
- is_prime=[False,False]+[True]*(MAX-1)
- primes=[]
- now=2
- while True:
- primes.append(now)
- for i in range(now*2,MAX+1,now):
- is_prime[i]=False
- now+=1
- try:
- while is_prime[now]==False:
- now+=1
- except:
- break
-
- while True:
- try:
- a,b=input().split()
- a,b=int(a),int(b)
- count=0
- for x in range(a,b+1):
- if x<=MAX:
- if x in primes:
- count+=1
- else:
- for prime in primes:
- if x%prime==0:
- break
- else: # a loop’s else clause runs when no break occurs
- count+=1
- print(count)
- except:
- break