Cod sursa(job #150212)

Utilizator Vlad-andreiVlad Fisca Vlad-andrei Data 6 martie 2008 19:03:50
Problema Factorial Scor 35
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.1 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>=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 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.