Pagini recente » Cod sursa (job #151095) | Cod sursa (job #23679) | Cod sursa (job #1255186) | Cod sursa (job #1607281) | Cod sursa (job #1664058)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
int a[5000005], b[5000005], c[5000005];
void preproc(int r)
{
for(int i = 1; i <= r; i++)
{
if(i % 2 == 0)
{
a[i] = a[i / 2] + 1;
}
if(i % 3 == 0)
{
b[i] = b[i / 3] + 1;
}
if(i % 5 == 0)
{
c[i] = c[i / 5] + 1;
}
}
}
int r, d, sol, pow_2, pow_3, pow_5;
int main()
{
fin >> r >> d;
preproc(r);
for(int i = 1; i <= r; i++)
{
pow_2 += a[r - i + 1] - a[i];
pow_3 += b[r - i + 1] - b[i];
pow_5 += c[r - i + 1] - c[i];
if(d == 2 && pow_2 > 0) sol++;
if(d == 3 && pow_3 > 0) sol++;
if(d == 4 && pow_2 > 1) sol++;
if(d == 5 && pow_5 > 0) sol++;
if(d == 6 && pow_2 > 0 && pow_3 > 0) sol++;
}
fout << sol;
return 0;
}