-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5615.py
More file actions
37 lines (29 loc) · 704 Bytes
/
5615.py
File metadata and controls
37 lines (29 loc) · 704 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
27
28
29
30
31
32
33
34
35
36
37
import sys
PRIME = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
def miller_rabin(n):
if n % 2 == 0 or n == 1:
return False
if n in PRIME:
return True
s, d = 1, n - 1
while d % 2 == 0:
d //= 2
s += 1
for a in PRIME:
x, y = pow(a, d, n), 0
for r in range(s):
y = pow(x, 2, n)
if y == 1 and x != 1 and x != n - 1:
return False
x = y
if y != 1:
return False
return True
n, s = int(sys.stdin.readline()), []
count = 0
for i in range(n):
s.append(int(sys.stdin.readline()))
for i in s:
if miller_rabin(2 * i + 1):
count += 1
print(count)