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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<cstdio>
#include<algorithm>

using namespace std;

typedef unsigned long long ull;

static ull t1[2520][512];
static ull t2[2520][512];
static ull pt1[2520][512];
static ull pt2[2520][512];
static ull wt[2520][512];

static ull (*tab)[512] = t1;
static ull (*tab2)[512] = t2;
static ull (*ptab)[512] = pt1;
static ull (*ptab2)[512] = pt2;
static ull (*wtab)[512] = wt;

static void przetworz(ull (*we)[512], ull pot, char c, ull (*wy)[512]){
    int p = (pot * c) % 2520;
    int ord = 0;

    if(c){
        ord = 1 << (c-1);
    }

    for(int i = 0; i < 2520; ++i){
        for(int j = 0; j < 512; ++j){
            int i2 = (i + p) % 2520;
            int j2 = j | ord;

            wy[i2][j2] += we[i][j];
        }
    }

}

static ull answer(ull n){
    ull pot = 1;
    for(int i = 0; i < 2520; ++i){
        for(int j = 0; j < 512; ++j){
            tab2[i][j] = 0;
            ptab2[i][j] = 0;
            wtab[i][j] = 0;
        }
    }

    tab2[0][0] = 1;
    ptab2[0][0] = 1;

    while(n){
        char c = n%10;
        n/=10;
        swap(tab, tab2);
        swap(ptab, ptab2);

        for(int i = 0; i < 2520; ++i){
            for(int j = 0; j < 512; ++j){
                tab2[i][j] = 0;
                ptab2[i][j] = 0;
            }
        }

        przetworz(ptab, pot, c, ptab2);

        for(char i = 1; i < c; ++i){
            przetworz(tab, pot, i, ptab2);
        }

        for(char i = 1; i < 10; ++i){
            przetworz(tab, pot, i, tab2);
        }

        przetworz(tab, pot, 0, wtab);

        pot *= 10;
    }

    przetworz(ptab2, pot, 0, wtab);

    ull counter = 0;

    for(int i = 0; i < 2520; ++i){
        for(int j = 1; j < 512; ++j){
            int j2 = j;
            int lj = 1;
            bool flag = false;

            while(j2){
                if(j2 & 1){
                    if(i % lj){
                        flag = true;
                        break;
                    }
                }

                j2 >>= 1;
                ++lj;
            }

            if(flag){
                continue;
            }

            counter += wtab[i][j];
        }

    }

    return counter;
}

static ull oczysc(ull n){
    while(true){
        bool flag = true;
        ull r = n;
        ull n2 = n;
        ull pot = 1;
        ull rpot = 1;

        while(n2){
            char c = n2 % 10;
            n2 /= 10;
            pot *= 10;

            if(!c){
                flag = false;
                r = n2;
                rpot = pot;
            }

        }


        if(flag)
            break;
        else
            n = r * rpot - 1;
    }
    return n;
}

int main(){
    ull l, r;
    scanf("%llu %llu", &l, &r);

    l = oczysc(l-1);
    r = oczysc(r);

    //printf("%llu %llu\n", l, r);
    //printf("%llu %llu\n", answer(l), answer(r));

    printf("%llu\n", answer(r) - answer(l));

    return 0;
}