Pagini recente » Rating eu tu el ea (eutu33) | Cod sursa (job #3292711) | Cod sursa (job #1092997) | Cod sursa (job #1349105) | Cod sursa (job #3274519)
#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 >> 1, 2);
return 0;
}