Cod sursa(job #451545)

Utilizator andrei.dAndrei Diaconeasa andrei.d Data 9 mai 2010 18:15:39
Problema Kperm Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <cstdio>

#define file_in "kperm.in"
#define file_out "kperm.out"

int n,k;

#define mod 666013

void citire()
{
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d %d", &n, &k);
}

inline int putere(int a, int b)
{
	if (b==0)
		return 1;
	if (b%2==0)
	{
		int x=putere(a,b/2);
		return (x%mod)*(x%mod);
	}
	else
	{
		int x=putere(a,b/2);
		return (x%mod)*(x%mod)*a;
	}
}

	

void solve()
{
	int c=n/k;
	int r=n%k;
	
	int i,suma=1;
	int p;
	
	if (k%2==1)
	{
	p=1;
    for (i=2;i<=r;++i)
		 p=(p*i)%mod;
	suma=(suma*p)%mod;
	p=1;
	for (i=2;i<=k-r;++i)
		p=(p*i)%mod;
	suma=(suma*p)%mod;
	p=1;
	for (i=2;i<=c+1;++i)
		 p=(p*i)%mod;
	p=putere(p,r);
	p%=mod;
	suma=(suma*p)%mod;
	p=1;
	for (i=2;i<=c;++i)
		 p=(p*i)%mod;
	p=putere(p,k-r);
	p%=mod;
	suma=(suma*p)%mod;
	printf("%d", suma);
	}
	else
		printf("0\n");
	
}

int main()
{
	citire();
	solve();
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
	
}