下面是我的程式:
def sieve_of_eratosthenes(limit):
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
p = 2
while p * p <= limit:
if is_prime[p]:
for multiple in range(p * p, limit + 1, p):
is_prime[multiple] = False
p += 1
primes = [p for p, prime in enumerate(is_prime) if prime]
return primes
limit = 1000000
primes = sieve_of_eratosthenes(limit)
while True:
a = int(input())
if a!=0:
if a in primes:
print('0')
else:
print('1')
else:
break
救我!大神!