Cod sursa(job #138487)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 18 februarie 2008 18:33:56
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <stdio.h>
#include <math.h>

long r, d, sol, v[9], t2, t3, t5, i;

long cuprinde(long num, long y) {
	long p = 0;
	while (num % y == 0) {
		num /= y;
		++p;
	}
	return p;
}

int main() {
	freopen("pascal.in", "r", stdin);
	freopen("pascal.out", "w", stdout);
	scanf("%ld%ld", &r, &d);
	if (d == 2) v[2] = 1;
	if (d == 3) v[3] = 1;
	if (d == 4) v[2] = 2;
	if (d == 5) v[5] = 1;
	if (d == 6) {
		v[2] = 1;
		v[3] = 1;
	}
	t2 = 0;t3 = 0;t5  = 0;
	for (i = 1; i <= r + 1; ++i) {
		if (t2 >= v[2] && t3 >= v[3] && t5 >= v[5]) {
			++sol;
			t2 -= v[2];
			t3 -= v[3];
			t5 -= v[5];
		}
		t2 += cuprinde(i, 2);
		t3 += cuprinde(i, 3);
		t5 += cuprinde(i, 5);
	}
	printf("%ld\n", sol);
	return 0;
}