Cod sursa(job #796142)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 10 octombrie 2012 19:02:20
Problema Pascal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("pascal.in");
ofstream fout("pascal.out");

int d[10];

int main()
{

	int R, D, sol = 0;

	fin >> R >> D;

	for (int k = 1; k < R; k++)
	{
		int N = R - k + 1;

		while (N % 2 == 0)
		{
		    N /= 2;
		    d[2]++;
        }

		while (N % 3 == 0)
		{
		    N /= 3;
		    d[3]++;
        }

		while (N % 5 == 0)
		{
		    N /= 5;
		    d[5]++;
        }

		int K = k;

		while (K % 2 == 0)
		{
		    K /= 2;
		    d[2]--;
        }

		while (K % 3 == 0)
		{
		    K /= 3;
            d[3]--;
		}
		while (K % 5 == 0)
        {
            K /= 5;
            d[5]--;
        }

		if (D == 4)
			{
                if (d[2] >= 2) sol++;
			}

		else if (D == 6)
		    {
                if (min(d[2],d[3]) > 0) sol++;
		    }

		 if (d[D]) sol++;
	}

	fout << sol;
	
	fin.close();
	fout.close();
	return 0;
}