CWAY - Đếm số đường đi trên đồ thị đầy đủ

Tác giả: flashmt

Ngôn ngữ: Pascal

const fi='';
      fo='';
      base=1000000;
      digit=6;
type bignum=array[0..1000] of longint;
var n:longint;
    re:bignum;

procedure rf;
begin
     assign(input,fi);
     reset(input);
     read(n);
     close(input);
end;

procedure plus(var a:bignum);
var i:longint;
begin
     for i:=1 to a[0] do
     begin
          inc(a[i]);
          if a[i]=base then a[i]:=0
          else break;
     end;
     if a[a[0]]=0 then
     begin
          inc(a[0]);
          a[a[0]]:=1;
     end;
end;

procedure multi(var a:bignum;b:longint);
var i,mem,t:longint;
begin
     mem:=0;
     for i:=1 to a[0] do
     begin
          t:=a[i]*b+mem;
          mem:=t div base;
          a[i]:=t mod base;
     end;
     if mem>0 then
     begin
          inc(a[0]);
          a[a[0]]:=mem;
     end;
end;

procedure pr;
var i:longint;
begin
     fillchar(re,sizeof(re),0);
     re[0]:=1; re[1]:=1;
     if n=2 then re[1]:=0;
     for i:=2 to n-2 do
     begin
          plus(re);
          multi(re,i);
     end;
     plus(re);
end;

procedure wf;
var i,j,t:longint; s:string;
begin
     assign(output,fo);
     rewrite(output);
     for i:=re[0] downto 1 do
     begin
          if i<re[0] then
          begin
               str(re[i],s);
               t:=length(s);
               for j:=t+1 to digit do write(0);
          end;
          write(re[i]);
     end;
     close(output);
end;

begin
     rf;
     pr;
     wf;
end.

Download