Cod sursa(job #136856)

Utilizator Vlad-andreiVlad Fisca Vlad-andrei Data 16 februarie 2008 10:53:45
Problema Factorial Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.12 kb
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>=10000000 then
     begin
          i:=40000010;
          gasit:=p-10000000;
     end else
         if p>=1000000 then
         begin
              i:=4000005;
              gasit:=p-1000000;
         end else
             if p>=100000 then
             begin
                  i:=400005;
                  gasit:=p-100000;
             end else
                 if p>=10000 then
                 begin
                      i:=40010;
                      gasit:=p-10000;
                 end else
                     if p>=1000 then
                     begin
                          i:=4005;
                          gasit:=p-1000;
                     end else
                         if p>=100 then
                         begin
                              i:=405;
                              gasit:=p-100;
                         end else
                             if p>=10 then
                             begin
                                  i:=45;
                                  gasit:=p-10;
                             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 3125=0) do
          begin
               i1:=i1 div 3125;
               gasit:=gasit+5;
          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.