Pagini recente » Cod sursa (job #825459) | Cod sursa (job #340225) | Cod sursa (job #3258912) | Cod sursa (job #1080335) | Cod sursa (job #827322)
Cod sursa(job #827322)
#include <cstdio>
using namespace std;
int Row, Factor[3] = {2, 3, 5}, Power[3], Solution;
inline int GetPower(int Factorial, int X) {
int power = 0, Y = X;
for (int p = 1; Y <= Factorial; ++p, Y *= X)
power += Factorial / Y;
return power;
}
inline int IsDivisible(int n, int k) {
int divisible = 1;
for (int i = 0; i < 3; ++i)
divisible &= (GetPower(n, Factor[i]) - GetPower(k, Factor[i]) - GetPower(n - k, Factor[i]) >= Power[i]);
return divisible;
}
void Solve() {
int n = Row;
for (int k = 1; k < n / 2; ++k)
Solution += IsDivisible(n, k);
Solution *= 2;
if (n % 2 == 0)
Solution += IsDivisible(n, n / 2);
}
void Read() {
freopen("pascal.in", "r", stdin);
int D; scanf("%d %d", &Row, &D);
for (int i = 0; i < 3; ++i)
for (; D % Factor[i] == 0; ++Power[i], D /= Factor[i]);
}
void Print() {
freopen("pascal.out", "w", stdout);
printf("%d\n", Solution);
}
int main() {
Read();
Solve();
Print();
return 0;
}