Cod sursa(job #602799)

Utilizator SteveStefan Eniceicu Steve Data 13 iulie 2011 07:46:00
Problema Pascal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream.h>

int main()
{
	long R, i, j, v[5000002], ptR=0, numere=0;
	int N;
	ifstream ins;
	ins.open("pascal.in");
	ins>>R>>N;
	ins.close();
	for (i=1; i<=R; i++)
	{
		v[i]=0;
		j=i;
		while (j)
		{
			j/=N;
			v[i]+=j;
		}
	}
	v[0]=1;
	ptR=v[R];
	if (R%2 == 1)
	{
		for (i=0; i <= R/2; i++)
		{
			if (ptR > v[i]+v[R-i])
			{
				numere+=2;
			}
		}
	}
	else
	{
		for (i=0; i < R/2; i++)
		{
			if (ptR > v[i]+v[R-i])
			{
				numere+=2;
			}
		}
		if (ptR > 2*v[R/2]) numere++;

	}
	ofstream ous;
	ous.open("pascal.out");
	ous<<numere;
	ous.close();
	return 0;
}