Cod sursa(job #859201)

Utilizator ELHoriaHoria Cretescu ELHoria Data 19 ianuarie 2013 20:36:21
Problema Pascal Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <fstream>

using namespace std;

ifstream cin("pascal.in");
ofstream cout("pascal.out");

const int rmax = 5000002;
int R, D;
int curr[3], cond[3];
const int divs[3] = {2,3,5};
int p[3][32];

int main()
{
	cin>>R>>D;
	for(int k = 0;k < 3;k++) {
		while(D%divs[k] == 0) {
			cond[k]++;
			D /= divs[k];
		}
	}
	p[0][0] = p[1][0] = p[2][0] = 1;
	for(int k = 1;k <= 25;k++) {
		p[0][k] = p[0][k - 1]*2;
	}
	for(int k = 1;k <= 16;k++) {
		p[1][k] = p[1][k - 1]*3;
		p[2][k] = p[2][k - 1]*5;
	}
	int ans = 0;
	int r = (R - 1)/2;
	for(int i = 1;i <= r;i++) {
		bool isDivisible = true;
		int aux[2] = {R - i + 1,i};
		for(int k = 0;k < 3;k++) {
			int j = 1;
			while(aux[0]%p[k][j] == 0) {
				curr[k]++;
				j++;
			}
			j = 1;
			while(aux[1]%p[k][j] == 0) {
				curr[k]--;
				j++;
			}
			isDivisible &= (curr[k] >= cond[k]);
		}
		ans += isDivisible + isDivisible;
	}
	if(R%2 == 0) {
		r++;
		bool isDivisible = true;
		int aux[2] = {R - r + 1,r};
		for(int k = 0;k < 3;k++) {
			int j = 1;
			while(aux[0]%p[k][j] == 0) {
				curr[k]++;
				j++;
			}
			j = 1;
			while(aux[1]%p[k][j] == 0) {
				curr[k]--;
				j++;
			}
			isDivisible &= (curr[k] >= cond[k]);
		}
		ans += isDivisible;
	}
	cout<<ans;
	return 0;
}