Cod sursa(job #796122)

Utilizator dariusdariusMarian Darius dariusdarius Data 10 octombrie 2012 18:17:40
Problema Pascal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <algorithm>
using namespace std;
int d[10];
int main()
{
	freopen("pascal.in","r",stdin);
	freopen("pascal.out","w",stdout);
	int R, D, sol = 0;
	scanf("%d%d",&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++;
		    }
		else
			if (d[D])
				sol++;
	}
	printf("%d\n",sol);
	return 0;
}