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>
#include<cstdlib>
std::string naStr(unsigned long long n);
inline int zwraca_cyfre(char);
int main() {
    using namespace std;
    ios_base::sync_with_stdio(0);
    unsigned long long k, granica_L, granica_P;
    string granicaL, granicaP;
    cin >> k >> granicaL >> granicaP;
    granica_L = strtol(granicaL.c_str(), NULL, 10);
    granica_P = strtol(granicaP.c_str(), NULL, 10);
    int cyfra;
    int suma = 0, wynik = 0, koniec = granicaL.size();
    for (unsigned long long lece_bo_chce = granica_L; lece_bo_chce <= granica_P; ) {
        for (int indeks = 0; indeks < koniec; indeks++)
            suma += (cyfra = zwraca_cyfre(granicaL[indeks]));
        if (k*suma == lece_bo_chce)
            wynik++;
        suma = 0;
        lece_bo_chce++;
        granicaL = naStr(lece_bo_chce);
        koniec = granicaL.size();
        }
    cout << wynik;
}
inline int zwraca_cyfre(char znak) {
    return (znak-int('0'))*(znak-int('0'));
}
std::string naStr(unsigned long long n)
{
     std::string tmp;
     do {
      tmp += n % 10 + 48;
      n -= n % 10;
     }
     while(n /= 10);
     return tmp;
}