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
//#include "stdafx.h"
#include <iostream>
#include <math.h>
//#include <time.h>

int suma(uint64_t liczba)
{
	int _suma = 0;
	do
	{
		int l = liczba % 10;
		_suma += pow(l, 2);
		liczba /= 10;
	} while (liczba != 0);

	return _suma;
}

int main()
{
	uint64_t k;
	uint64_t a;
	uint64_t b;

	std::cin >> k;
	std::cin >> a;
	std::cin >> b;

	uint64_t n = a;
	uint64_t fn = 0;
	int ilosc = 0;
	//clock_t tStart = clock();

	while (n <= b)
	{
		fn = suma(n);

		if (k*fn == n)
			ilosc++;
		n++;
	}
	std::cout << ilosc << std::endl;
	//std::cout << "Czas: " << ((double)(clock() - tStart) / CLOCKS_PER_SEC) << std::endl;
	//system("PAUSE");
    return 0;
}