Pagini recente » Cod sursa (job #1459984) | Cod sursa (job #989991) | Cod sursa (job #127963) | Cod sursa (job #559871) | Cod sursa (job #831497)
Cod sursa(job #831497)
#include <cstdio>
const int MAX_FACT = 6;
int fact[MAX_FACT];
void factors(int x, int add) {
while (x % 2 == 0) {
fact[2] += add;
x >>= 1;
}
while (x % 3 == 0) {
fact[3] += add;
x /= 3;
}
while (x % 5 == 0) {
fact[5] += add;
x /= 5;
}
}
inline bool ok(int d) {
if (d == 4)
return fact[2] > 1;
if (d == 6)
return fact[3] > 0 && fact[2] > 0;
return fact[d] > 0;
}
void solve(int r, int d) {
int half = r >> 1, res = 0;
for (int i = 1; i <= half; ++i) {
int top = r - i + 1, bottom = i;
factors(top, 1);
factors(bottom, -1);
if (ok(d))
res += 2;
}
if (r % 2 == 0 && ok(d))
--res;
printf("%d\n", res);
}
int main() {
freopen("pascal.in", "r", stdin);
freopen("pascal.out", "w", stdout);
int r, d;
scanf("%d%d", &r, &d);
solve(r, d);
}