Cod sursa(job #189917)

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

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

int vd[10],v[10]; 
int p,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<=5;++i)
		while(!(d%i))
		{
			++vd[i];
			d/=i;
		}	
}
void add(int xx)
{
	for(int j=2;j<=5;++j)
	{
		p=0;
		while(!(xx%j))
		{
			xx/=j;
			++p;
		}
		v[j]+=p;
	}
}
void sub(int yy)
{
	for(int j=2;j<=5;++j)
	{
		p=0;
		while(!(yy%j))
		{
			yy/=j;
			++p;
		}
		v[j]-=p;
	}
}		
void check()
{
	for(int i=2;i<=5;++i)
		if(v[i]<vd[i])
			return;
	++nr;	
}	
void solve()
{
	x=r+1; y=0;
	int to=(r-1)/2;
	if(r%2==0 && d==2)
		nr=to;
	else
	{
		for(int i=1;i<=to;++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;
}