Pagini recente » Cod sursa (job #1115296) | Cod sursa (job #150480) | Cod sursa (job #312608) | Cod sursa (job #1266349) | Cod sursa (job #1411388)
#include <fstream>
using namespace std;
const int MOD = 666013;
const char IN[] = "kperm.in";
const char OUT[] = "kperm.out";
int main(int argc, const char * argv[]) {
ifstream fi (IN);
ofstream fo (OUT);
int N,K;
fi >> N >> K; fi.close();
long long int ANS = 1;
if (!(K & 1)) fo << 0;
else
{
int cat = N / K, rest = N % K, a,b;
a = b = 1;
for (int i = 1; i <= cat; ++i)
a = (a * i) % MOD;
b = ( a * (cat + 1) ) % MOD;
for (int i=1; i <= rest; ++i)
ANS = (ANS * i) % MOD, ANS = (ANS * b) % MOD;
for (int i=1; i <= K - rest; ++i)
ANS = (ANS * i) % MOD, ANS = (ANS * a) % MOD;
fo << ANS;
}
fo << endl;
fo.close();
return 0;
}