Cod sursa(job #477066)

Utilizator blasterzMircea Dima blasterz Data 13 august 2010 12:10:24
Problema Kperm Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <cstring>
#define mod 666013

int n, K;

int main ()
{
	freopen ("kperm.in", "r", stdin);
	freopen ("kperm.out", "w", stdout);

	scanf ("%d %d\n", &n, &K);

	int C = n / K;
	int R = n % K;

	if (K % 2 == 0)
	{
		printf ("0\n");
		return 0;
	}

	int sol = 1;
	int i;

	for (i = 2; i <= R; ++i)
		sol *= i,
		sol %= mod;

	int kr = 1;

	for (i = 2; i <= K - R; ++i)
		kr *= i,
		kr %= mod;

	sol *= kr;
	sol %= mod;


	int c1 = 1;


	for (i = 2; i <= C + 1; ++i)
		c1 *= i,
		c1 %= mod;

	int c11 = c1;

	for (i = 2; i <= R; ++i)
		c1 *= c11,
		c1 %= mod;

	sol *= c1;
	sol %= mod;

	int cc = 1;
	for (i = 2; i <= C; ++i)
		cc *= i,
		cc %= mod;

	int ccc = cc;

	for (i = 2; i <= K - R; ++i)		
		cc *= ccc,
		cc %= mod;
	
	sol *= cc;
	sol %= mod;


	printf ("%d\n", sol);
		
	return 0;
}