1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
static const unsigned long long M = 1000000000000000000ULL;
int d(unsigned long long x){
    int s=0,m;
    while(x){m=x%10;s+=m*m;x/=10;}
    return s;
}
int main() {
    unsigned long long k,a,b,x; int f,s=0;
    scanf("%llu%llu%llu",&k,&a,&b);
    for(f=1;f<=1377;++f){
        if(k>M/f)continue;
        x=k*f;
        if(x>=a&&x<=b&&d(x)==f)++s;
    }
    printf("%d\n",s);
    return 0;
}