Pagini recente » Cod sursa (job #2524515) | Cod sursa (job #893958) | Cod sursa (job #2822296) | Cod sursa (job #2535689) | Cod sursa (job #2650083)
#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;
}
int main()
{
long long r; int 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(long long j = 0; j < r/2; j++)
{
if(gfact(r, d) - gfact(r-j, d) - gfact(j, d) > cutoff)
cnt ++;
}
cnt *= 2;
if(r%2 == 0)
if(gfact(r, d) - gfact(r/2, d) - gfact(r/2, d) > cutoff) cnt++;
out << cnt;
}