Pagini recente » Cod sursa (job #553010) | Cod sursa (job #2656841) | Cod sursa (job #1410242) | Cod sursa (job #1239310) | Cod sursa (job #601485)
Cod sursa(job #601485)
var a:array[1..20] of int64;
P:int64; N,K:longint; i:byte; F:text;
function CheckZero(N:longint):longint;
var r:int64;
begin
i:=1;
r:=0;
while a[i]<N do
begin
r:=r+N div a[i];
inc(i);
end;
CheckZero:=r;
end;
Begin
a[1]:=5;
N:=0;
assign(F, 'fact.in');
reset(F);
readln(F, p);
close(F);
for i:=2 to 20 do
a[i]:=a[i-1]*5;
K:=1;
if P>10 then
while K<P do begin
N:=N+5*((P-K) div 3);
K:=CheckZero(N);
end
else
while K<P do begin
N:=N+5;
K:=CheckZero(N);
end;
if ChecKZero(N-2)=P then N:=N-2
else if CheckZero(n-1)=P then N:=N-1
else if CheckZero(N)<>P then N:=-1;
assign(F, 'fact.out');
rewrite(F);
write(F, N);
close(F);
end.