Cod sursa(job #2705329)

Utilizator gasparrobert95Gaspar Robert Andrei gasparrobert95 Data 12 februarie 2021 13:25:24
Problema Pascal Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
ll r, d, rez, put[5000005], put2[5000005];

int main() {
    fin >> r >> d;
    ll ori = 0, ori2 = 0, dc = d, d2 = 0;
    if (d == 6)
        d = 2, d2 = 3;
    if (d == 4)
        d = 2;
    for (int i = 1; i <= r + 1; ++i) {
        ll aux = i;
        while (aux % d == 0) {
            aux /= d;
            ++ori;
        }
        aux = i;
        while (d2 != 0 && aux % d2 == 0) {
            aux /= d2;
            ++ori2;
        }
        put2[i] = ori2;
        put[i] = ori;
    }
    bool ok = false;
    for (int j = 1; j <= r / 2; ++j) {
        ll p = put[r] - put[j] - put[r - j];
        if (dc == 6)
            p = min(put[r] - put[j] - put[r - j], put2[r] - put2[j] - put2[r - j]);
        if ((dc != 4 && p > 0) || (dc == 4 && p > 1)) {
            ++rez;
            if (j == r / 2)
                ok = true;
        }
    }
    rez *= 2;
    if (r % 2 == 0 && ok)
        --rez;
    fout << max((ll)0, rez);
    return 0;
}