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

using namespace std;

int main()
{
	unsigned long long int a, b, k;
	cin >> k >> a >> b;

	unsigned long long int n = ((a%k==0)?a:(a+(k-a%k)));
	unsigned long long int result=0;
	
	while (n <= k*81*(log10(n)+1) && n<=b)
	{
		unsigned long long int nCopy=n;
		int sum=0;
		while (nCopy != 0)
		{
			sum += (nCopy%10)*(nCopy%10);
			nCopy /= 10;
		}
		
		if (sum*k == n)
			result++;

		n += k;
	}
	
	cout << result << endl;
}