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
var
  k, a, b : int64;
  kwadrat, ilosc : longint;
  i, j, cyfr_i, poj : integer;
  lan_k, lan_i : string;
    
begin
  ilosc := 0;
  read(k);
  read(a);
  read(b);
  str(k,lan_k);
//  if k <= 1377 then
  
//  begin
  
  for i:=1 to 1377 do
    begin
	  kwadrat := 0;
	  str(k * i,lan_i);
	  cyfr_i := length(lan_i);
      if k * i < a then
	    continue
	  else
	    if k * i > b then
		  break
		else
		  begin
		    for j := 1 to cyfr_i do
			  begin
				begin
			      val(copy(lan_i,j,1),poj);
				  kwadrat := kwadrat + (poj * poj);
		        end;
			  end;
			if kwadrat = i then
              begin
			    ilosc := ilosc + 1;
//				writeln(kwadrat);
			  end;
		  end;
//	end;
	
  end;
	
	writeln(ilosc);
end.