aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/abigail/python/ch-1.py
blob: ebb8821ddc74d945ad97c3e590a151841de71091 (plain)
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
#!/opt/local/bin/python

#
# See ../README.md
#

#
# Run as: python ch-1.py < input-file
#

#     
# For a description of the algorithm, and the proof why this is correct:
# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-113-1.html
#  

import fileinput

gcds = [0, 1, 2, 1, 2, 5, 2, 1, 2, 1]

for line in fileinput . input ():
    (N, D) = line . split ();
    N = int (N)
    D = int (D)
    if D == 0:
        print (1 if N >= 100 or N % 10 == 0 else 0)
        continue

    if N >= D * 10:
        print (1)
        continue

    done = False
    for i in range (0, D // gcds [D]):
        T = N - 10 * i - D
        if T >= 0 and T % D == 0:
            print (1)
            done = True
            break
    if not done:
        print (0)