Pagini recente » Cod sursa (job #370859) | Cod sursa (job #2579808) | Cod sursa (job #1197620) | Cod sursa (job #3161109) | Cod sursa (job #3225985)
#include <fstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define ll long long
using namespace std;
ifstream cin("pascal.in");
ofstream cout("pascal.out");
int n, D, answer, good_middle;
int expF;
int Legendre(int p, int n)
{
int curent_p = p, cnt_p = 0;
while(curent_p <= n)
{
cnt_p += n / curent_p;
curent_p *= p;
}
return cnt_p;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> D;
expF = Legendre(D, n);
for(int i = 0; i <= n / 2; i++)
{
int good = 1;
int curent_exp1 = Legendre(D, i);
int curent_exp2 = Legendre(D, n - i);
if(expF - curent_exp1 - curent_exp2 < 1)
good = 0;
else if(n % 2 == 0 && i == n / 2)
good_middle = 1;
answer += good;
}
cout << answer * 2 - good_middle;
return 0;
}