Cod sursa(job #26305)

Utilizator hitmannCiocas Radu hitmann Data 5 martie 2007 14:08:02
Problema Kperm Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.92 kb
program kperm;
var n,k,r,c:int64;
    h1,h2,h3,h4,h5:int64;
    g:text;
procedure citire;
var f:text;
begin
assign(f,'kperm.in'); reset(f); read(f,n,k); close(f); end;
function fac(i:int64):int64;
var x:int64;
    j:longint;
begin
x:=1;
for j:=1 to i do
               begin
               x:=x*j;
               if x>=666013 then x:=x mod 666013;
               end;
fac:=x;
end;
function put(n,m:int64):int64;
var x:int64;
    i:longint;
begin
x:=1;
for i:=1 to m do begin
                 x:=x*n;
                 if x>=666013 then x:=x mod 666013;
                 end;
put:=x;
end;
begin {pp}
citire;  c:=n div k; r:=n mod k;
assign(g,'kperm.out'); rewrite(g);
if k mod 2= 0 then write(g,'0')
else
begin
 h1:=fac(r);
 h2:=fac(k-r);
 h3:=put(fac(c+1),r);
 h4:=put(fac(c),k-r);
 h5:=((h1 mod 666013)*(h2 mod 666013)*(h3 mod 666013)*(h4 mod 666013))mod 666013;
 write(g,h5);
 end;
close(g);
end.