Cod sursa(job #2650083)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 17 septembrie 2020 14:48:03
Problema Pascal Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("pascal.in");
ofstream out("pascal.out");

long long gfact(long long fact, int base)
{
    long long nr_div = 0;
    while(fact)
    {
        nr_div += fact / base; fact /= base;
    }

    return nr_div;
}

int main()
{
    long long r; int d; in >> r >> d;
    long long cnt = 0;
    int cutoff;

    if(d == 4) cutoff = 1;
    else cutoff = 0;

    if(d == 6) d = 3;
    if(d == 4) d = 2;

    for(long long j = 0; j < r/2; j++)
    {
        if(gfact(r, d) - gfact(r-j, d) - gfact(j, d) > cutoff)
            cnt ++;
    }

    cnt *= 2;
    if(r%2 == 0)
    if(gfact(r, d) - gfact(r/2, d) - gfact(r/2, d) > cutoff) cnt++;

    out << cnt;
}