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
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main(int argc, char** argv) {
	long long int a = 0, b = 0, k = 0, suma = 0, ilosc = 0, x = 0;
	cin>>k>>a>>b;

	
	for(long long int i = a; i <= b; i++)
	{
		a = i;
		x = i;
		while(a>0)
		{
			a %= 10;
			x -= a;
			x /= 10;
			a *= a;
			suma += a;
			if(suma>i) continue;
			a = x;
		}
		suma *= k;
		if(suma == i) ilosc++;
		suma = 0;
		
	}
	
	cout<<ilosc;

	

	
	
	return 0;
}