Cod sursa(job #3357377)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 9 iunie 2026 10:03:56
Problema Pascal Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <bits/stdc++.h>

using namespace std;

#define USE_STD_IO 0
#if USE_STD_IO
    #define fin cin
    #define fout cout
#else
    ifstream fin("pascal.in");
    ofstream fout("pascal.out");
#endif // USE_STD_IO

typedef array<int, 3> Fact;
const int DESC[] = {2, 3, 5};
int n, k, i, rasp;

static inline Fact Desc(int n) {
    Fact fact = {0, 0, 0};
    for(int i = 0; i < 3; i++) {
        while(0 == n % DESC[i]) {
            fact[i]++;
            n /= DESC[i];
        }
    }
    return fact;
}

static inline bool Divi(const Fact& a, const Fact& d) {
    for(int i = 0; i < 3; i++) {
        if(a[i] < d[i]) return false;
    }
    return true;
}

static inline void Add(Fact& f, const Fact& a, int semn) {
    for(int i = 0; i < 3; i++) {
        f[i] += semn * a[i];
    }
}

int main() {
    #if USE_STD_IO
        ios_base::sync_with_stdio(false);
    #endif // USE_STD_IO
    fin.tie(NULL);
    fout.tie(NULL);

    fin >> n >> k;

    const Fact factK = Desc(k);
    Fact factCur = {0, 0, 0};

    for(i = 1; i < n; i++) {
        Add(factCur, Desc(n - i + 1),  1);
        Add(factCur, Desc(    i    ), -1);
        if(Divi(factCur, factK)) {
            rasp++;
        }
    }
    fout << rasp;

    return 0;
}