Cod sursa(job #176703)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 11 aprilie 2008 16:08:57
Problema 12-Perm Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.68 kb
const modulo=1048575;

var a:array[0..3] of longint;
    f,g:text;
    i,n:longint;

begin
 assign(f,'12perm.in'); reset(f);
 assign(g,'12perm.out'); rewrite(g);
 read(f,n);
 a[0]:=1; a[1]:=2; a[2]:=6; a[3]:=12;  //a[4]  a[5]  a[6]  a[7]
 for i:=5 to n do begin
  case i and 3 of
  1: a[0]:=(a[3]+a[1]+(i-2) shl 1) and modulo;
  2: a[1]:=(a[0]+a[2]+(i-2) shl 1) and modulo;
  3: a[2]:=(a[1]+a[3]+(i-2) shl 1) and modulo;
  0: a[3]:=(a[2]+a[0]+(i-2) shl 1) and modulo;
  end;
 end;
 if n<=4 then
  writeln(g,a[n])
 else begin
  case i and 3 of
  1: writeln(g,a[0]);
  2: writeln(g,a[1]);
  3: writeln(g,a[2]);
  0: writeln(g,a[3]);
  end;
 end;
 close(f); close(g);
end.