-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb53.py
More file actions
26 lines (23 loc) · 743 Bytes
/
b53.py
File metadata and controls
26 lines (23 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
from bisect import bisect_right
from itertools import chain, compress
print("Input an even number (0 to exit):")
ub = 50000
is_prime = [0, 0, 1, 1] + [0] * (ub - 3)
is_prime[5::6] = is_prime[7::6] = [1] * int(ub / 6)
primes = [2, 3]
append = primes.append
for n in chain(range(5, ub, 6), range(7, ub, 6)):
if is_prime[n]:
append(n)
is_prime[n * 3::n * 2] = [0] * ((ub - n) // (n * 2))
primes.sort()
for n in map(int, sys.stdin):
if not n:
break
if n % 2:
print("Number of combinations:")
print(is_prime[n - 2])
else:
print("Number of combinations:")
print(len([1 for p in primes[:bisect_right(primes, n / 2)] if is_prime[n - p]]))