Cod sursa(job #163757)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 23 martie 2008 10:11:29
Problema Sandokan Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.31 kb
var v,p:array[0..5001] of longint;
    f,g:text;
    i,j,n,x,k,w:longint;
    prod:int64;

procedure ciur(n:longint);
 var i,j:longint;
 begin
  i:=1;
  while (i*i) shl 1+i shl 1<=n do begin
   if (v[i shr 3] shr (i and 7)) and 1=0 then begin
    j:=i*i shl 1 + i shl 1;
    while (j shl 1+1<=n) do begin
     v[j shr 3]:=v[j shr 3] or (1 shl (j and 7));
     j:=j+i shl 1+1;
    end;
   end;
   inc(i);
  end;
  p[1]:=2;
  p[0]:=1;
  i:=1;
  while i shl 1+1<=n do begin
   if (v[i shr 3] shr (i and 7)) and 1=0 then begin
    inc(p[0]);
    p[p[0]]:=i shl 1+1;
   end;
   inc(i);
  end;
 end;

procedure descomp(x:longint);
 var i:longint;
 begin
  i:=1;
  while (x<>1)  do begin
   while (x mod p[i]=0) do begin
    x:=x div p[i];
    inc(v[i],w);
   end;
   inc(i);
  end;
 end;


procedure comb(n,k:longint);
 var i:longint;
 begin
  w:=1;
  for i:=k+1 to n do
   descomp(i);
  w:=-1;
  for i:=1 to n-k do
   descomp(i);
 end;

begin
 assign(f,'sandokan.in'); reset(f);
 assign(g,'sandokan.out'); rewrite(g);
 read(f,n,k);
 ciur(5000);
 for i:=1 to 5000 do
  v[i]:=0;
 x:=n;
 while (x>=k) do
  x:=x-k+1;
 n:=n-1;
 x:=x-1;
 comb(n,x);
 prod:=1;
 for i:=1 to p[0] do
  for j:=1 to v[i] do
   prod:=(prod*p[i]) mod 2000003;
 writeln(g,prod);
 close(f); close(g);
end.