Cod sursa(job #166630)

Utilizator raduzerRadu Zernoveanu raduzer Data 28 martie 2008 11:14:09
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <stdio.h>

int n,d,a[8],b[8],c[8];

int main()
{
	freopen("pascal.in","r",stdin);
	freopen("pascal.out","w",stdout);
	scanf("%d%d",&n,&d);
	int i,j;
	for (i=2; i<=d; ++i)
	{
		while (d%i==0) 
		{
			++a[i];
			d/=i;
		}
	}
	int x;
	int sol=0;
	for (i=1; i<n; ++i)
	{
		x=n-i+1;
		for (j=2; j<=5; ++j)
		{
			while (x%j==0)
			{
				++b[j];
				x/=j;
			}
			c[j]=b[j];
		}
		x=i;
		for (j=2; j<=5; ++j)
		{
			while (x%j==0)
			{
				--c[j];
				x/=j;
			}
		}
		int q=0;
		for (j=2; j<=5; ++j)
		{
			if (a[j]>c[j])
			{
				q=1;
				break;
			}
			b[j]=c[j];
		}
		if (q==0) ++sol;
	}
	printf("%d\n",sol);
	return 0;
}