Pagini recente » Cod sursa (job #2618655) | Cod sursa (job #2485297) | Cod sursa (job #3211758) | Cod sursa (job #2759523) | Cod sursa (job #2650109)
#include <bits/stdc++.h>
using namespace std;
ifstream in("pascal.in");
ofstream out("pascal.out");
long long gfact(long long fact, int base)
{
long long nr_div = 0;
while(fact)
{
nr_div += fact / base; fact /= base;
}
return nr_div;
}
long long precalc[5000005];
int main()
{
long long r; long long d; in >> r >> d;
long long cnt = 0;
int cutoff;
if(d == 4) cutoff = 1;
else cutoff = 0;
if(d == 6) d = 3;
if(d == 4) d = 2;
//for(int i = 0; i <= r; i++)
// precalc[i] = gfact(i, d);
for(long long divs = d; divs <= r; divs*=d)
for(long long index = divs; index <= r; index += divs)
precalc[index] += 1;
for(long long index = 1; index <= r; index++)
precalc[index] += precalc[index-1];
for(long long j = 0; j < r; j++)
{
if(precalc[r] - precalc[r-j] - precalc[j] > cutoff)
cnt ++;
}
out << cnt;
}