Pagini recente » Cod sursa (job #30944) | Cod sursa (job #1626185) | Cod sursa (job #1422094) | Cod sursa (job #2585819) | Cod sursa (job #26330)
Cod sursa(job #26330)
const p=666013;
var f:text;
a1,a2,n,k,r,i,c:longint;
sol:int64;
function go(a,b:longint):longint;
var h:longint;
begin
if b=0 then go:=1
else if b mod 2=0 then
begin
h:=go(a,b div 2);
go:=(h*h) mod p;
end
else begin
h:=go(a,b div 2);
go:=(h*h*a) mod p;
end;
end;
begin
assign(f,'kperm.in');
reset(f);
readln(f,n,k);
close(f);
if (k mod 2)=0 then
begin
sol:=0;
end
else begin
r:=n mod k;
c:=n div k;
a1:=1;
for i:=2 to c do
a1:=(a1*i) mod p;
sol:=go(a1*(c+1),r);
sol:=(sol*go(a1,k-r)) mod p;
for i:=2 to r do sol:=(sol*i) mod p;
for i:=2 to (k-r) do sol:=(sol*i) mod p;
end;
assign(f,'kperm.out');
rewrite(f);
writeln(f,sol);
close(f);
end.