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

using namespace std;

int main()
{
    long long int k,a,b,temp,temp2;
    int result(0), divisor;
    cin >> k >> a >> b;
    if(k==1)
    {
        if(a==1) result=1;
        else result=0;
    }
    else
    {
        for(long long int i=(a%k==0?a:((a/k)+1)*k); i<=b; i+=k)
        {
            temp=i/k;
            temp2=i;
            while(temp2)
            {
                divisor=temp2%10;
                temp2/=10;

                temp-=(divisor*divisor);
                if(temp<0) break;
                else if(temp==0)
                {
                    if(temp2!=0) continue;
                    result++;
                    break;
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}