Pagini recente » Cod sursa (job #829257) | Cod sursa (job #2686702) | Cod sursa (job #2582223) | Cod sursa (job #192171) | Cod sursa (job #601475)
Cod sursa(job #601475)
var a:array[1..15] 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:=40000010;
assign(F, 'fact.in');
reset(F);
readln(F, p);
close(F);
for i:=2 to 15 do
a[i]:=a[i-1]*5;
K:=1;
while K<P do begin
K:=CheckZero(N);
N:=N+5*(P-K) div 4;
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.