Cod sursa(job #3148976)

Utilizator patcasrarespatcas rares danut patcasrares Data 5 septembrie 2023 15:49:40
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
const int DN = 5e6 + 5;
long long R,D, sol, main_two, main_five, two, five, main_three, three, d2, d3, d5;
int dp[6][DN];

long long get_pow(long long N, long long O) {
	
	
	return dp[O][N];
}

int main() {
	// your code goes here
	fin >> R >> D;
	
  d2 = 0;
  if (D % 2 == 0) 
    d2 ++;
  if (D % 4 == 0) 
    d2 ++;
  if (D % 3 == 0) 
    d3 ++;
  if (D % 5 == 0) 
    d5 ++;
  
  for(int i=0;i< 3;i++) {
    int put = 2;
    if (i == 1) 
      put = 3;
    
    if (i == 2) 
      put = 5;
    
    for(int j=1;j<=R;j++) {
      dp[put][j] = dp[put][j-1];
      int aux = j;
      while (aux % put == 0) {
        dp[put][j] += 1;
        aux /= put;
      }
    }

  }
  
  main_two = get_pow(R, 2);
	main_five = get_pow(R, 5);
  main_three = get_pow(R, 3);
  
	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;
}