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
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <queue>
#include <utility>

#define debug(...) fprintf(stderr, __VA_ARGS__)

uint64_t get_int(){
    char d;
    static uint64_t tmp;
    tmp = 0;
    while((d=getchar())>='0'){
        tmp = (tmp<<3)+(tmp<<1)+d-'0';
    }
    return tmp;
}

typedef std::pair<uint64_t, uint64_t> pair;

inline bool czyLiczba(uint64_t x, uint64_t flag){
    if(flag & (1<<6)){
        if(x%6 != 0){
            return false;
        }
        flag &= ~5;
    }  
    if(flag & (1<<8)){
        if((x & 7) != 0){
            return false;
        }
        flag &= ~6;
    }
    if(flag & (1<<4)){
        if((x & 3) != 0){
            return false;
        }
        flag &= ~2;
    }
    if(flag & (1<<2)){
        if((x & 1) != 0){
            return false;
        }
    }
    if(flag & (1<<9)){
        if(x%9 != 0){
            return false;
        }
        flag &= ~3;
    }
    if(flag & (1<<3)){
        if(x%3 != 0){
            return false;
        }
    }
    if(flag & (1<<5)){
        if(x%5 != 0){
            return false;
        }
    }
    if(flag & (1<<7)){
        if(x%7 != 0){
            return false;
        }
    }

    return true;
}

int main(){
    uint64_t l = get_int();
    uint64_t r = get_int();

    // debug("L: %d R: %d\n", l, r);
    std::queue<pair> q;
    for(uint64_t i=1;i<10;i++){
        q.emplace(i, 1<<i);
    }

    uint64_t counter = 0, flag, tmp;
    for(uint64_t i=l;i<=r;i++){
        flag = 0;
        tmp = i;
        // debug("4 %d\n", i);
        while(tmp > 0){
            auto d = div(tmp, 10);
            if(d.rem != 0)
                flag |= (1<<(d.rem));
            else{
                flag = 0;
                break;
            }
            tmp = d.quot;
        }
        if(flag == 0){
            continue;
        }
        // debug("5 %d\n", i);
        if(czyLiczba(i, flag)) {
            // debug("Liczba potyczkowa\n");
            counter++;
        }
    }
    printf("%llu", counter);
}