Cod sursa(job #223896)

Utilizator mebobBota Bogdan mebob Data 29 noiembrie 2008 16:27:44
Problema Pascal Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream.h>

int fact(int a)
{
	int i, f=1;
	for (i=1; i<=a; i++)
		{
		f=f*i;
		}
	return f;
}

int poz(int i, int j)
{
	int poz;
	poz=fact(i)/(fact(i-j)*fact(j));
	return poz;
}

int main()
{
	long int r, j, pozi, d, k=-1;
	ifstream in("pascal.in");
	ofstream out ("pascal.out");
	in>>r;
	in>>d;
	if ((r>=0)&&(r<=5000000)&&(d>=2)&&(d<=6))
	{
	for (j=1; j<=r+1; j++)
		{
		pozi=poz(r, j);
		if (pozi%d==0) k++;
		}
	out<<k;
	}
	else
	{
	out<<"out of range";
	}
	return 0;
}