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
47
48
49
50
51
52
53
54
55
56
57
//Visual Studio 2015; C++ Console App
#include <iostream>
#include <cstdlib>
//Trace On
using namespace std;

//Integer's Length
int intlength(int n)
{
	int len = 1;

	if (n > 0) {
		for (len = 0; n > 0; len++) {
			n = n / 10;
		}
	}

	return len;

}

//f(n) function
int f(int n)
{
	int result = 0;
	int l = intlength(n);
	for (int i = 0; i < l; i++)
	{
		int d = n % 10;
		n = n / 10;
		result += (d*d);

	}

	return result;
}

//I am the bone of my code
int main()
{
	int a,k,b;
	cin >> k;
	cin >> a;
	cin >> b;

	int result = 0;
	for (int i = a; i <= b; i++)
	{
		if (k * f(i) == i)
		{
			//cout << "(n = " << i << ")";
			result++;
		}
	}
	cout<< result;
	system("pause");
}