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
#include <cstdio>

#define LL long long

int sum(LL i){
    int s=0;
    while(i>0){
        s+=(i%10)*(i%10);
        i/=10;
    }
    return s;
}


int main(){
    LL k,a,b;
    scanf("%lld%lld%lld",&k,&a,&b);
    int counter=0;
    for(LL i=1;i<81*19;++i){
        if(i*k<a)continue;
        if(i*k>b)break;
        counter+=(sum(i*k)==i);
    }
    printf("%d",counter);
    return 0;
}