Pagini recente » Cod sursa (job #2823359) | Cod sursa (job #1540629) | Cod sursa (job #2746804) | Cod sursa (job #2026303) | Cod sursa (job #1561251)
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <fstream>
#define MAX_N 5000010
using namespace std;
int divs[7] = {0, 0, 2, 3, 2, 5, 2};
int mapPrimeFact[7] = {-1, -1, 0, 1, 0, 2, 0};
int primeFact[3] = {2, 3, 5};
int n, d, apar, apar2;
char nPut[3][MAX_N];
void addMult(int x, int sign) {
apar += sign * nPut[mapPrimeFact[d]][x];
if (d == 6)
apar2 += sign * nPut[1][x];
}
int main() {
ifstream cin("pascal.in");
freopen("pascal.out", "w", stdout);
cin >> n >> d;
for (int i = 1; i <= n; i++)
if (i % divs[d] == 0)
nPut[mapPrimeFact[d]][i] = nPut[mapPrimeFact[d]][i / divs[d]] + 1;
if (d == 6)
for (int i = 1; i <= n; i++)
if (i % 3 == 0)
nPut[1][i] = nPut[1][i / 3] + 1;
int sol = 0;
for (int i = 1, j = n; j; i++, j--) {
addMult(j, 1);
addMult(i, -1);
if (d == 4)
sol += (apar > 1);
else if (d == 6)
sol += (apar && apar2);
else sol += (bool) apar;
}
printf("%d\n", sol);
return 0;
}