Pagini recente » Cod sursa (job #1654224) | Cod sursa (job #906070) | Cod sursa (job #1932854) | Cod sursa (job #548072) | Cod sursa (job #60536)
Cod sursa(job #60536)
program fact;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ add your units here };
var
p:int64;
function zero(x:int64):int64;
var
c:int64;
begin
c:=0;
while x div 5 > 0 do
begin
c:=c+ x div 5;
x:= x div 5;
end;
zero:=c;
end;
{procedure calc(x,y:int64);
var
d:int64;
z:int64;
begin
if (x<>y) or (abs(x-y)<>1) then
begin
d:=(x+y) div 2;
z:=zero(d);
if (d mod 5 = 0) and (z = p) then
case d of
0: writeln('-1')
else writeln(d);
end else
if z<p
then calc(d+1,y)
else calc(x,d-1)
end else writeln('-1');
end;}
procedure calc;
var
x,y,z,d:int64;
begin
x:=1;
y:=10000000000000000000;
while (z<>p) or (x<y) do
begin
d:=(x+y) div 2;
z:=zero(d);
if (d mod 5 = 0) and (z = p) then
case d of
0: begin writeln('-1'); exit; end;
else begin writeln(d); exit; end;
end else
if z<p
then x:=d+1
else y:=d-1;
end;
writeln('-1');
end;
begin
assign(input,'fact.in');reset(input);
assign(output,'fact.out');rewrite(output);
while not eof do
begin
readln(p);
calc;
end;
close(output);
end.