Cod sursa(job #29603)

Utilizator skyelHighScore skyel Data 9 martie 2007 17:31:53
Problema Kperm Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#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;
	}