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
#include<iostream>
using namespace std;

int main(){
    long long int a,b,k,n, buf, m, it=0, sum_n=0, wyn=0, cyfra;
    cin>>k>>a>>b;
    buf=b;
    do{
        it++;
        buf/=10;
    }while(buf>0);
    m=k*it*81;
    if(b<m)
        m=b;
    buf = a%k;
    it = k-buf;
    a+=it;
    for(long long int i=a; i<=m; i+=k){
        n=i;
        do{
            cyfra = n%10;
            n/=10;
            sum_n+=cyfra*cyfra;
        }while(n>0);
        if(k*(sum_n)==i){
            wyn++;
        }
        sum_n = 0;
    }
    cout<<wyn;
    return 0;
}