Cod sursa(job #26114)

Utilizator thestickTudor A thestick Data 5 martie 2007 10:52:56
Problema Kperm Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <stdio.h>
long x[5000],i,n,k,tz=0;

int bun(long k)
{long t,i;t=1;i=0;while((t)&&(i<k))	{	if(x[i]==x[k]) t=0;	else i++;	}return t;return 1;}

int bun2()
{
long i,s=0;

for(i=0;i<k;i++)
s+=x[i];

if(s%k!=0)return 0;
for(i=k;i<n;i++)
{
if(s%k!=0)return 0;
s+=x[i];
s-=x[i-k];
}
return 1;
}

void cit()
{
long i;
FILE *f;
f=fopen("kperm.in","r");
fscanf(f,"%d %d",&n,&k);
fclose(f);
for(i=0;i<=n;i++) x[i]=0;
}

void tip()
{
long i;
tz=(tz+1)%666013;
}

int main()
{
cit();
i=0;
do
{
	do
	{
		x[i]++;
		if(x[i]>n)
			{
			x[i]=0;
			i--;
			}
		else
			{
				if(bun(i))
				i++;
			}
	}
	while((i<n)&&(i!=-1));

	if(i>=n)
	{
        if(bun2())
	tip();
	i=n-1;
	}
}
while(i!=-1);
FILE *f;
f=fopen("kperm.out","w");
fprintf(f,"%d\n",(tz/2)%666013);
fclose(f);
return 0;
}