Pagini recente » Cod sursa (job #881716) | Cod sursa (job #3161044) | Cod sursa (job #2314369) | Cod sursa (job #1653687) | Cod sursa (job #29603)
Cod sursa(job #29603)
#include<math.h>
#include<fstream.h>
#define mod 666013
#define input "kperm.in"
#define output "kperm.out"
int a[5000],uzt[5000],n,b;
long h;
long fact(int k)
{
long s=1,i;
for(i=1;i<=k;i++)
{
s*=i;
if(s>mod)
s=s%mod;
}
return s;
}
int main()
{
int i,c,r,t;
ifstream fin(input);
ofstream fout(output);
fin>>n>>b;
c=n/b;
r=n-n/b;
if(b%2==0)
fout<<"0";
else
{
h=(fact(r)%mod);
h=h%mod;
h*=(fact(b-r))%mod;
h=h%mod;
t=fact(c+1)%mod;
h*=pow(t,r);
h=h%mod;
h*=pow(fact(c),b-r);
h=h%mod;
}
fout<<h<<"\n";
return 0;
}