-
Notifications
You must be signed in to change notification settings - Fork 94
/
Sherlock and Divisors.py
52 lines (40 loc) · 1.1 KB
/
Sherlock and Divisors.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Problem Statement
Watson gives an integer N to Sherlock and asks him: What is the number of divisors of N that are divisible by 2?.
Input Format
First line contains T, the number of testcases. This is followed by T lines each containing an integer N.
"""
__author__ = 'Danyang'
import math
class Solution(object):
def solve(self, cipher):
"""
Brute Force
:param cipher: the cipher
"""
N = cipher
if N % 2 == 1:
return 0
cnt = 0
i = 1
sq = math.sqrt(N)
while i <= sq:
if N % i == 0:
if i % 2 == 0:
cnt += 1
other = N / i
if other != i and other % 2 == 0:
cnt += 1
i += 1
return cnt
if __name__ == "__main__":
import sys
f = open("1.in", "r")
# f = sys.stdin
testcases = int(f.readline().strip())
for t in xrange(testcases):
# construct cipher
cipher = int(f.readline().strip())
# solve
s = "%s\n" % (Solution().solve(cipher))
print s,