Cod sursa(job #2786419)

Utilizator UnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage Data 20 octombrie 2021 21:48:12
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <bits/stdc++.h>

using namespace std;

inline void Open(const string Name) {
    #ifndef ONLINE_JUDGE
        (void)!freopen((Name + ".in").c_str(), "r", stdin);
        (void)!freopen((Name + ".out").c_str(), "w", stdout);
    #endif
}

array <int, 3> d[5000001];
int N, dd, ord, ans, ans1, ans2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    Open("pascal");

    cin >> N >> dd;

    for(int i = 1;i <= N;i++) {
        if(i % 2 == 0) d[i][0] = d[i / 2][0] + 1;
        if(i % 3 == 0) d[i][1] = d[i / 3][1] + 1;
        if(i % 5 == 0) d[i][2] = d[i / 5][2] + 1;
    }

    if(dd == 2 || dd == 3 || dd == 5) {
        dd -= 2, dd -= (dd == 3);
        for(int i = 1;i <= N;i++) {
            ans1 += d[N - i + 1][dd] - d[i][dd];
            ans += (ans1 > 0);
        }
    }

    if(dd == 4) {
        for(int i = 1;i <= N;i++) {
            ans1 += d[N - i + 1][0] - d[i][0];
            ans += (ans1 > 1);
        }
    }

    if(dd == 6) {
        for(int i = 1;i <= N;i++) {
            ans1 += d[N - i + 1][0] - d[i][0];
            ans2 += d[N - i + 1][1] - d[i][1];
            ans += (ans1 > 0 && ans2 > 0);
        }
    }

    cout << ans;

    return 0;
}