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

typedef long long int int64;

int f( int64 n )
{
	int result = 0;
	while ( n )
	{
		const int digit = n % 10;
		result += digit * digit;
		n /= 10;
	}

	return result;
}

int solve( const int64 k, const int64 a, const int64 b )
{
	const int64 maxfn = 1 + 18 * ( 9 * 9 );

	int count = 0;
	for ( int fn = 1; fn <= maxfn; ++fn )
	{
		const int64 n = k * fn;
		if ( k <= n && fn <= n && a <= n && n <= b && f( n ) == fn )
		{
			++count;
		}
	}

	return count;
}

int main()
{
	int64 k, a, b;
	std::cin >> k >> a >> b;
	std::cout << solve( k, a, b );
	return 0;
}