Cod sursa(job #360432)

Utilizator funkydvdIancu David Traian funkydvd Data 31 octombrie 2009 15:02:00
Problema Pascal Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include<fstream>
using namespace std;
ifstream f1 ("pascal.in");
ofstream f2 ("pascal.out");
int r,p1,p2,p11,p12,g;
int desc(int k,int d)
{
	int k1,i;
	p2=0;
	int x=(r-k)/d;
	p2=x;
	k1=d;
	while (x) {k1=k1*d; x=(r-k)/k1; p2+=x;}
	x=k/d;
	p2+=x;
	k1=d;
	while (x) {k1=k1*d; x=k/k1; p2+=x;}
	if (d==3 || d==5) if (p1-p2>0) return 1;
	if (d==2 && g==0) if (p1-p2>0) return 1;
	if (d==2 && g==1) if (p1-p2>1) return 1;
	return 0; 
}
int desc2(int k)
{
	p1=p11;
	int f=desc(k,2);
	if (f==0) return 0;
	p1=p12;
	
	f=desc(k,3);
	return f;
}
int main()
{
	int i,c,sol=0,x;
	f1>>r>>c;
	int k1;
	if (c==4) {c=2; g=1;}
	if (c!=6)
	{
		x=r/c;
		p1=x;
		k1=c;
		while (x) 
		{
			k1=k1*c; 
			x=r/k1; 
			p1+=x;
		}
	}
	else 
	{
		x=r/2;
		p11=x;
		k1=2;
		while (x) 
		{
			k1=k1*2; 
			x=r/k1; 
			p11+=x;
		}
		x=r/3;
		p12=x;
		k1=3;
		while (x) 
		{
			k1=k1*3; 
			x=r/k1; 
			p12+=x;
		}
	}
	for (i=0; i<=r; i++)
		if (c!=6) 
			if (desc(i,c)) sol++;
			    else;
		else if (desc2(i) ) sol++;
	f2<<sol;
}