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
#include <iostream>
#include <cstdint>
#include <utility>

using namespace std;



uint64_t sum_sqr_dig(uint64_t  n)
{
    uint64_t res=0;
    while(n>0)
    {
        res+=(n%10)*(n%10);
        n=n/10;
    }
    return res;
}

int main()
{
    uint64_t k, a, b;
    int counter=0;

    cin>>k>>a>>b;

    for (uint64_t i = 1 ; i<=min((uint64_t)9*9*18ul,b/k); i++)
    {
        uint64_t n = i*k;
        uint64_t x= sum_sqr_dig(n);
        if ((x==i) && (a<=n) && (n<=b) )
        {
            counter++;
        }
    }
    cout<<counter<<endl;

}