Cod sursa(job #731821)

Utilizator robertpoeRobert Poenaru robertpoe Data 9 aprilie 2012 11:50:03
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream>
using namespace std;
ifstream f("pascal.in");
ofstream g("pascal.out");
int n,d,val1,val2,v[7],rez,r,i;
void desc()
{
	while(val1%2==0)
		v[2]++, val1=val1/2;
	while(val1%3==0)
		v[3]++, val1=val1/3;
	while(val1%5==0)
		v[5]++, val1=val1/5;
	while(val2%2==0)
		v[2]--, val2=val2/2;
	while(val2%3==0)
		v[3]--, val2=val2/3;
	while(val2%5==0)
		v[5]--, val2=val2/5;
}
int main()
{
	f>>n>>d;
	r=n;
	for(i=1; i<=r/2; i++, n--)
	{
		val1=n;
		val2=i;
		desc();
		if((d==6&&v[2]>0&&v[3]>0)||(d==4&&v[2]>1)||v[d]>0)
			rez=rez+2;
	}
	if(((d==6&&v[2]>0&&v[3]>0)||(d==4&&v[2]>1)||v[d]>0)&&r%2==0)
		rez--;
	g<<rez;
}