Afişează mesaje
Pagini: [1]
1  infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Răspuns: 006 Factorial : Aprilie 04, 2013, 23:13:15
Cred că nu merge ceva aici:
Cod:
program fact;
var
 vector:array[0..12] of longint= (1, 6, 31, 156, 781, 3906, 19531, 97656, 488281, 2441406, 12207031, 61035156, 1000000001);
 p,k,zerouri:longint;
 marime,i:byte;
 fin,fout:text;
begin
 assign(fin,'fact.in');
 reset(fin);
 read(fin,p);
 close(fin);
 marime:=0;
 while p>vector[marime] do
  marime:=marime+1;
 zerouri:=p;
 for i:=marime downto 1 do
  begin
   zerouri:=zerouri-p div vector[i];
   if p mod vector[i]>=vector[i]-i then
    p:=-1;
  end;
 assign(fout,'fact.out');
 rewrite(fout);
 if p=0 then
  write(fout,1)
 else
  if p=-1 then
   write(fout,-1)
  else
   write(fout,zerouri*5);
 close(fout);
end.
Pagini: [1]
Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines