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


using namespace std;

long long k, a, b;

void read()
{
    cin >> k >> a >> b;
}

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

int number_of_solutions(long long x, long long y, long long z)
{
    int answer=0;
    const int RANGE=1900;
    for(long long i=0;i<RANGE; i++)
    {
        if(x*i>=y && z>=x*i)
        {
            if(sum_digit_squared(x*i)==i)
            {
                answer++;
            }
        }
        if(x*i>z)
        {
            break;
        }
    }
    return answer;
}

int main()
{
    read();
    cout << number_of_solutions(k, a, b) << endl;
    return 0;
}