Cod sursa(job #26297)

Utilizator hitmannCiocas Radu hitmann Data 5 martie 2007 14:01:40
Problema Kperm Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.88 kb
program kperm;
var n,k,r,c:integer;
    h1,h2,h3,h4,h5:int64;
procedure citire;
var f:text;
begin
assign(f,'kperm.in'); reset(f); read(f,n,k); close(f); end;
function fac(i:longint):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:longint):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(output,'kperm.out'); rewrite(output);
 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(h5);
close(output);
end.