Pagini recente » Cod sursa (job #1285973) | Cod sursa (job #1061674) | Cod sursa (job #1367927) | Cod sursa (job #2642869) | Cod sursa (job #893573)
Cod sursa(job #893573)
#include <fstream>
using namespace std;
const int prim[] = {2, 3, 5};
int R, D;
int times[3], total; // 2, 3 sau 5 (ca divizori primi)
int p0[5000002], p1[5000002], p2[5000002];
bool done[5000002];
int main()
{
ifstream fin("pascal.in");
ofstream fout("pascal.out");
fin >> R >> D;
for (int i = 1; i < R; ++i)
{
int now1 = R - i + 1, now2 = i;
if (!done[now1])
{
int auxn = now1;
while (now1 % 2 == 0) ++p0[auxn], now1 /= 2;
while (now1 % 3 == 0) ++p1[auxn], now1 /= 3;
while (now1 % 5 == 0) ++p2[auxn], now1 /= 5;
done[auxn] = true;
}
if (!done[now2])
{
int auxn = now2;
while (now2 % 2 == 0) ++p0[auxn], now2 /= 2;
while (now2 % 3 == 0) ++p1[auxn], now2 /= 3;
while (now2 % 5 == 0) ++p2[auxn], now2 /= 5;
done[auxn] = true;
}
now1 = i;
for (int j = now1 * 2; j < R && !done[j]; j *= 2)
{
p0[j] = p0[j / 2] + 1;
p1[j] = p1[j / 2];
p2[j] = p2[j / 2];
done[j] = true;
}
for (int j = now1 * 3; j < R && !done[j]; j *= 3)
{
p0[j] = p0[j / 3];
p1[j] = p1[j / 3] + 1;
p2[j] = p2[j / 3];
done[j] = true;
}
for (int j = now1 * 5; j < R && !done[j]; j *= 5)
{
p0[j] = p0[j / 5];
p1[j] = p1[j / 5];
p2[j] = p2[j / 5] + 1;
done[j] = true;
}
now1 = R - i + 1, now2 = i;
times[0] += p0[now1];
times[1] += p1[now1];
times[2] += p2[now1];
times[0] -= p0[now2];
times[1] -= p1[now2];
times[2] -= p2[now2];
if (D == 2 && times[0]) ++total;
if (D == 3 && times[1]) ++total;
if (D == 4 && times[0] >= 2) ++total;
if (D == 5 && times[2]) ++total;
if (D == 6 && times[0] && times[1]) ++total;
}
fout << total;
fin.close();
fout.close();
}