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
#include <iostream>
#include <math.h>

using namespace std;

int main() {

	unsigned long long a, b, k;

	cin >> k >> a >> b;

	unsigned short solutions = 0;

	for (unsigned long long number = a; number <= b; number++) {

		unsigned char digits = floor(log10(number)) + 1;
		unsigned short total = 0;

		for (int i = 0; i < digits; i++) {
			total += pow(floor(number % (int)pow(10, i + 1) / pow(10, i)), 2);
		}

		if (number == (total * k))
			solutions++;

	}

	cout << solutions;

	return 0;
}