Cod sursa(job #3274520)
Utilizator | Data | 6 februarie 2025 23:26:59 | |
---|---|---|---|
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)) / 2;
else fout << solutie(n >> 1, 2);
return 0;
}