Cod sursa(job #693393)

Utilizator iu.ciocoiuIulian iu.ciocoiu Data 27 februarie 2012 12:13:04
Problema Factorial Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.93 kb
program suma;
var f,g:text;
    i,p,nr,aux,x:longint;
begin
assign (f,'fact.in'); reset (f);
assign (g,'fact.out'); rewrite (g);
read (f,p);
if (p mod 6=5) then write (g,'-1')
               else if (p=0) then write (g,'1')
else begin i:=1;
           nr:=0;
           while (i+nr<p) do begin aux:=i;
                                   x:=0;
                                   while (aux mod 5=0) do begin x:=x+1;
                                                                aux:=aux div 5;
                                                          end;
                                   if (x>=1) then nr:=nr+x;
                                   //   (trunc(int(ln (5*i)/ln(5))) >=2) then nr:=nr+1;
                                   i:=i+1;
                             end;
           i:=i-1;
           if (i+nr=p) then write (g,i*5)
                       else write (g,'-1');
     end;
close (f);
close (g);
end.