Cod sursa(job #189913)

Utilizator andrei-alphaAndrei-Bogdan Antonescu andrei-alpha Data 19 mai 2008 00:01:33
Problema Pascal Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <stdio.h>
#define DIV_MAX 5500000
#define IN "pascal.in"
#define OUT "pascal.out"

//i!/((i-j)!*j!)

int vd[10],v[DIV_MAX]; 
int x,y,d,r,nr;
void scan()
{
	freopen(IN, "r",stdin);
	freopen(OUT, "w",stdout);
	scanf("%d%d", &r,&d);
	for(int i=2;i<=6;++i)
		while(!(d%i))
		{
			++vd[i];
			d/=i;
		}	
}
void add(int xx)
{
	for(int j=2;j<=6;++j)
	{
		int p=0;
		if(!(xx%j))
		{
			while(!(xx%j))
			{
				xx/=j;
				++p;
			}
			v[j]+=p;
		}
		if(xx==1)
			break;
	}
	if(xx>1)
		++v[xx];
}
void sub(int yy)
{
	for(int j=2;j<=6;++j)
	{
		int p=0;
		if(!(yy%j))
		{
			while(!(yy%j))
			{
				yy/=j;
				++p;
			}
			v[j]-=p;
		}
		if(yy==1)
			break;
	}
	if(yy>1)
		--v[yy];
}	
void check()
{
	for(int i=2;i<=6;++i)
		if(v[i]<vd[i])
			return;
	++nr;	
}	
void solve()
{
	x=r; y=1;
	for(int i=1;i<=(r-1)/2;++i)
	{
		add(x--);
		sub(y++);
		check();
	}
	nr*=2;
	if(!(r%2))
	{
		add(x--);
		sub(y++);
		check();
	}
	printf("%d\n", nr);
	
	
}
int main()
{
	scan();
	solve();
	return 0;
}