Cod sursa(job #191174)
Utilizator | Data | 25 mai 2008 16:16:31 | |
---|---|---|---|
Problema | Factorial | Scor | 35 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 2.94 kb |
program psacal;
var f,g:text; p:int64;
x,aux,nr,d,k:int64;
u,v:array[1..10] of int64;
procedure test;
begin
k:=p;
d:=0;
while p<>0 do
begin
d:=d+1;
p:=p div 10;
end;
p:=k;
k:=u[d+1];
x:=v[d+1];
if k<>p then
repeat
aux:=x;
while (aux mod 5=0) and (aux<>0) do
begin
k:=k-1;
aux:=aux div 5;
end;
x:=x-5;
until (k=p) or (k<p);
if k=p then write(g,x)
else write(g,-1);
end;
procedure test1;
begin
if k<>p then
repeat
aux:=x;
while (aux mod 5=0) and (aux<>0) do
begin
k:=k-1;
aux:=aux div 5;
end;
x:=x-5;
until (k=p) or (k<p);
if k=p then write(g,x)
else write(g,-1);
end;
begin
assign(f,'fact.in'); reset(f);
assign(g,'fact.out'); rewrite(g);
read(f,p);
if p<=100000 then
begin
u[1]:=2; v[1]:=10;
u[2]:=24; v[2]:=100;
u[3]:=249; v[3]:=1000;
u[4]:=2499; v[4]:=10000;
u[5]:=24999; v[5]:=100000;
if p=0 then write(g,1)
else test;
end
else
begin
if (p>24999) and (p<=124999) then
begin
k:=124999;
x:=500000;
test1;
end;
if (p>124999) and (p<=249998) then
begin
k:=249998;
x:=1000000;
test1;
end;
if (p>249998) and (p<=1249998) then
begin
k:=1249998;
x:=5000000;
test1;
end;
if (p>1249998) and (p<=2499999) then
begin
k:=2499999;
x:=10000000;
test1;
end;
if (p>2499999) and (p<=12499999) then
begin
k:=12499999;
x:=50000000;
test1;
end;
if (p>12499999) and (p<=24999999) then
begin
k:=24999999;
x:=100000000;
test1;
end;
if (p>24999999) and (p<=124999999) then
begin
k:=124999999;
x:=500000000;
test1;
end;
if (p>124999999) and (p<=249999999) then
begin
k:=249999999;
x:=1000000000;
test1;
end;
if p>249999999 then write(g,-1);
end;
close(f);
close(g);
end.