Cod sursa(job #3148968)

Utilizator patcasrarespatcas rares danut patcasrares Data 5 septembrie 2023 15:18:08
Problema Pascal Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
long long R,D, sol, main_two, main_five, two, five, main_three, three, d2, d3, d5;

long long get_pow(long long N, long long O) {
	long long nr = 0, cnt = 0, P = O;
	while(P <= N) {
    cnt += 1;
		nr += N / P;
		P = P * O;

   // if (cnt > 3)
     // break;
	}
	
	return nr;
}

int main() {
	// your code goes here
	fin >> R >> D;
	
	main_two = get_pow(R, 2);
	main_five = get_pow(R, 5);
  main_three = get_pow(R, 3);
  d2 = 0;
  if (D % 2 == 0) 
    d2 ++;
  if (D % 4 == 0) 
    d2 ++;
  if (D % 3 == 0) 
    d3 ++;
  if (D % 5 == 0) 
    d5 ++;
	for (int j = 0; j<= R; j++) {
    if (D % 2 == 0){
		  two = main_two - get_pow(j, 2) - get_pow(R - j, 2);
    }
    if (D % 5 == 0){
		  five = main_five - get_pow(j, 5) - get_pow(R - j, 5);
    }
    if (D % 3 == 0){
      three = main_three - get_pow(j, 3) - get_pow(R - j, 3);
    }
		if (two >= d2 && five >= d5 && three >= d3)
			sol++;
	}
	fout << sol;
	return 0;
}