Pagini recente » Cod sursa (job #3990) | Cod sursa (job #1954164) | Cod sursa (job #1511408) | Cod sursa (job #29495) | Cod sursa (job #138430)
Cod sursa(job #138430)
program factorial;
var f,g:text; {1 cifra de 0... 1*2*3*4*5}
i,p,gasit,nr,i1:longint; {4 cifre de 0 ... 5*..10*..15..20}
begin
assign(f,'fact.in');
assign(g,'fact.out');
reset(f);
rewrite(g);
read(f,p);
gasit:=0;
i:=0;
if p>=99999999 then
begin
i:=400000010;
gasit:=99999999;
end else
if p>=49999999 then
begin
i:=200000005;
gasit:=49999999;
end else
if p>=9999999 then
begin
i:=40000005;
gasit:=9999999;
end else
if p>=4999999 then
begin
i:=20000000;
gasit:=4999999;
end else
if p>=999999 then
begin
i:=4000000;
gasit:=999999;
end else
if p>=499999 then
begin
i:=2000000;
gasit:=499999;
end else
if p>=99999 then
begin
i:=400000;
gasit:=99999;
end else
if p>=49999 then
begin
i:=200005;
gasit:=49999;
end else
if p>=9999 then
begin
i:=40005;
gasit:=9999;
end else
if p>=999 then
begin
i:=4000;
gasit:=999;
end else
if p>=99 then
begin
i:=400;
gasit:=99;
end;
while(gasit<p) do
begin
i:=i+5;
i1:=i;
{cautam toti divizorii de 5,
adica de cate ori se imparte la 5 produsul nostru,
mergem din 5 in 5 cu cautarea 5,10, 15.....}
while (i1 mod 1953125=0) do
begin
i1:=i1 div 1953125;
gasit:=gasit+9;
end;
while (i1 mod 390625=0) do
begin
i1:=i1 div 390625;
gasit:=gasit+8;
end;
while (i1 mod 78125=0) do
begin
i1:=i1 div 78125;
gasit:=gasit+7;
end;
while (i1 mod 15625=0) do
begin
i1:=i1 div 15625;
gasit:=gasit+6;
end;
while (i1 mod 3125=0) do
begin
i1:=i1 div 3125;
gasit:=gasit+5;
end;
while (i1 mod 625=0) do
begin
i1:=i1 div 625;
gasit:=gasit+4;
end;
while (i1 mod 125=0) do
begin
i1:=i1 div 125;
gasit:=gasit+3;
end;
while (i1 mod 5=0) do
begin
i1:=i1 div 5;
gasit:=gasit+1;
end;
end;
if p=0 then nr:=1
else nr:=i;
write(g,nr);
close(f);
closE(g);
end.