Cod sursa(job #2703656)

Utilizator gasparrobert95Gaspar Robert Andrei gasparrobert95 Data 8 februarie 2021 21:32:22
Problema Pascal Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
ll n, d, rez;

int main() {
    fin >> n >> d;
    if (d > n) {
        fout << 0;
        return 0;
    }
    ll put = 0, putd2 = 0, d1 = d, d2 = d;
    if (d1 == 4)
        d1 = 2, d2 = 2;
    if (d1 == 6)
        d1 = 2, d2 = 3;
    ll aux = d1;
    while (aux <= n) {
        put += n / aux;
        aux *= d1;
    }
    aux = d2;
    while (aux <= n) {
        putd2 += n / aux;
        aux *= d2;
    }
    for (int j = 0; j <= n / 2; ++j) {
        aux = d1;
        ll put2 = 0, put2d2 = 0;
        while (aux <= n - j) {
            put2 += (n - j) / aux;
            if (aux <= j)
                put2 += j / aux;
            aux *= d1;
        }
        if (d == 4 || d == 6) {
            aux = d2;
            while (aux <= n - j) {
                put2d2 += (n - j) / aux;
                if (aux <= j)
                    put2d2 += j / aux;
                aux *= d2;
            }
        }
        if ((d != 4 && d != 6 && put - put2 > 0) || ((d == 4 || d == 6) && min(put - put2, putd2 - put2d2) > 0))
            ++rez;
    }
    rez *= 2;
    if (n % 2 == 0)
        --rez;
    fout << rez;
    return 0;
}