Cod sursa(job #601475)

Utilizator DarkWishMasterCebotari Vlad DarkWishMaster Data 6 iulie 2011 19:41:23
Problema Factorial Scor 75
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
var a:array[1..15] of int64;
    P:int64; N,K:longint; i:byte; F:text;
 function CheckZero(N:longint):longint;
  var r:int64;
   begin
    i:=1;
     r:=0;
     while a[i]<N do
      begin
      r:=r+N div a[i];
      inc(i);
     end;
    CheckZero:=r;
  end;
Begin
a[1]:=5;
N:=40000010;
assign(F, 'fact.in');
reset(F);
readln(F, p);
close(F);
 for i:=2 to 15 do
 a[i]:=a[i-1]*5;
K:=1;
while K<P do begin
 K:=CheckZero(N);
 N:=N+5*(P-K) div 4;
end;
if ChecKZero(N-2)=P then N:=N-2
 else if CheckZero(n-1)=P then N:=N-1
   else if CheckZero(N)<>P then N:=-1;
assign(F, 'fact.out');
rewrite(F);
write(F, N);
close(F);
end.