Cod sursa(job #3274518)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 6 februarie 2025 23:21:43
Problema Pascal Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;

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

long long solutie(int n, int p)
{
    long long sol = 1;
    int aux = n;
    while(n)
    {
        sol *= n % p + 1;
        n /= p;
    }
    sol = aux + 1 - sol;
    return sol;
}

int main()
{
    int n, p;
    fin >> n >> p;
    if(p == 2 || p == 3 || p == 5) fout << solutie(n, p);
    else if(p == 6) fout << solutie(n, 2) + solutie(n, 3);
    else fout << solutie(n, 2) / 2;
    return 0;
}