Pagini recente » Cod sursa (job #2047059) | Cod sursa (job #891104) | Cod sursa (job #1469390) | Cod sursa (job #1553010) | Cod sursa (job #2335720)
#include <fstream>
#define LIM 666013
using namespace std;
ifstream in("kperm.in");
ofstream out("kperm.out");
int fact(int n)
{
long long R=1;
for(int i=2;i<=n;i++) R=(R*i)%LIM;
return R;
}
int pow(long long b,int e)
{
long long R=1;
while(e)
{
if(e&1) R=(R*b)%LIM;
b=(b*b)%LIM; e>>=1;
}
return R;
}
int main()
{
int n,k,r;
in>>n>>k;
r=n%k;
long long p1=pow(fact(n/k) ,k-r);
long long p2=pow(fact(n/k+1),r );
long long p3=fact(r);
long long p4=fact(k-r);
long long R=(((((p1*p2)%LIM)*p3)%LIM)*p4)%LIM;
if(k%2==0 && k%4!=0) out<<0;
else out<<R;
}