aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/abigail/node/ch-1.js
blob: e755524470013126d5d6441b8677f45027c4baee (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
#!/usr/local/bin/node

//
// See ../README.md
//

//
// Run as: node ch-1.js < 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
//  

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

require ('readline')
. createInterface ({input: process . stdin})   
. on ('line', _ => {
    let [N, D] = _ . split (/\s+/) . map (_ => +_)
    if (D == 0) {
        console . log (N >= 100 || N % 10 == 0 ? 1 : 0)
        return
    }
    if (N >= D * 10) {
        console . log (1)
        return
    }
    for (let i = 0; i < D / gcds [D]; i ++) {
        let T = N - 10 * i - D
        if (T >= 0 && T % D == 0) {
            console . log (1)
            return
        }
    }
    console . log (0)
})