Pagini recente » Cod sursa (job #2148418) | Cod sursa (job #2282189) | Cod sursa (job #1016294) | Cod sursa (job #2124284) | Cod sursa (job #26316)
Cod sursa(job #26316)
const p=666013;
var f:text;
a1,a2,n,k,r,r2,i,sol:longint;
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;
r2:=k-r;
sol:=1;
a1:=1;
for i:=2 to n div k do
a1:=(a1*i) mod p;
a1:=go(a1,r2);
a2:=go(a1*((n div k)+1),r);
a1:=(a1*a2) mod p;
sol:=(sol*a1) mod p;
for i:=2 to r do sol:=(sol*i) mod p;
for i:=2 to r2 do sol:=(sol*i) mod p;
end;
assign(f,'kperm.out');
rewrite(f);
writeln(f,sol);
close(f);
end.