Pagini recente » Cod sursa (job #2484693) | Cod sursa (job #2647553) | Cod sursa (job #3208270) | Cod sursa (job #1897864) | Cod sursa (job #333300)
Cod sursa(job #333300)
Program fact;
var f,g:text; np,p:longint;
procedure initiere;
begin
assign (f,'fact.in'); reset (f);
assign (g,'fact.out'); rewrite (g);
readln (f,p);
np:=0;
end;
procedure incheiere;
begin
close (f); close (g);
end;
function valoare (x:longint):longint;
var y:longint;
begin
y:=0;
while (x div 5)<>0 do begin
y:=y+x div 5;
x:=x div 5;
end;
valoare:=y;
end;
procedure calcul (x,y:longint);
begin
if y=x+1 then
if (valoare (x)<>p) and (valoare (y)<>p) then writeln (g,-1) else begin
if valoare (x)=p then writeln (g,x) else
if valoare (y)=p then writeln (g,y);
end
else begin
if (valoare (x)<=p) and (valoare ((x+y) div 2)>=p) then calcul (x,(x+y) div 2);
if (valoare ((x+y) div 2)<p) and (valoare (y)>=p) then calcul ((x+y) div 2,y);
end;
end;
begin
initiere;
calcul (1,500000000);
incheiere;
end.