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
#include <iostream>
#include <string>

using namespace std;

int pot[18]={1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163};

bool check(unsigned long long x)
{
    string tab=to_string(x);
    int suma = 0;
    bool czk[11]={0,0,0,0,0,0,0,0,0,0,0};

    for(int i=0; i<tab.length(); i++)
    {suma+=((int)tab[i])-'0';
    czk[(int)tab[i]-'0']=true;
    if(czk[0]) return false;
    }

    if(czk[5]&&tab.back()!='5') return false;
    if(czk[2]&&((int)tab.back()-'0')%2!=0) return false;
    if(czk[3]&&suma%3!=0) return false;
    if(czk[9]&&suma%9!=0) return false;
    if(czk[6]&&(((int)tab.back()-'0')%2!=0||suma%3!=0)) return false;
    if(x>10)
    {
        if(czk[4]&&((int)tab.back()-'0'+((int)tab[tab.length()-2]-'0')*10)%4!=0) return false; 
    }
    if(x>100){
        if(czk[8]&&((((int)tab[tab.length()-3]-'0')*100)+(int)tab.back()-'0'+((int)tab[tab.length()-2]-'0')*10)%8!=0) return false;
    }else if(czk[8]&&x%8!=0) return false;

    if(czk[7])
    {
            int pom=0;
            for(int i = tab.length()-1; i>=0; i--)
                pom+=(((int)tab[i]-'0')*pot[tab.length()-1-i]);
            if(pom%7!=0) return false;


    }

//for(int i=0; i<=tab.length(); i++)
    //cout<<tab[i];
    //cout<<'\n';
    return true;
    
}


int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
unsigned long long l,r;
unsigned long long ans=0;
cin>>l>>r;

for(unsigned long long i=l; i<=r; i++)
if(check(i)){ 
ans++;
}
cout<<ans;


    return 0;
}