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

const long long maxl=std::numeric_limits<long long>::max();

long long digitsq(long long n) {
   long long sum=0;
   while (n!=0) {
      sum+=(n%10)*(n%10);
      n/=10;
   }
   return sum;
}

int main() {
long long k,a,b;
std::cin >> k >> a >> b;
int count=0;
for (long long i=1; i<=18*81; ++i) {
   if(k<=maxl/i) {
      long long n=k*i;
      if(k<=maxl/digitsq(n) && k*digitsq(n)==n && n >= a && n <= b)
          count++;
   }
}

std::cout << count << std::endl;
return 0;
}