Pagini recente » Cod sursa (job #2102321) | Cod sursa (job #985690) | Cod sursa (job #644679) | Cod sursa (job #2268117) | Cod sursa (job #14565)
Cod sursa(job #14565)
#include <stdio.h>
int p, r, d, c, i, ct1, ct2, ct3, a, b, ct, a2, b2, a3, b3, lim, verif;
//char s[5000001][1];
int fact (int n, int p)
{
int i, sol = 0, t = p;
while (p <= n)
{ sol += n / p;
p *= t;
}
return sol;
}
int
main ()
{
freopen ("pascal.in", "rt", stdin);
freopen ("pascal.out", "wt", stdout);
scanf ("%d%d", &r, &d);
if (r == 2 && d == 2)
{ printf ("1\n"); return 0; }
lim = r / 2;
if (d == 6)
{ a = fact (r, 2);
b = fact (r, 3);
for (c = 0; c <= lim; c++)
{ a2 = fact (r - c, 2);
b2 = fact (r - c, 3);
a3 = fact (c, 2);
b3 = fact (c, 3);
if (a > a2 + a3 && b > b2 + b3)
ct++;
if (c == lim && r % 2 == 0 && a > a2 + a3 && b > b2 + b3)
verif = 1;
}
}
else if (d == 4)
{ ct1 = fact (r, 2);
for (c = 0; c <= lim; c++)
{ ct2 = fact (r - c, 2);
ct3 = fact (c, 2);
if (ct1 > ct2 + ct3 + 1)
ct++;
if (c == lim && r % 2 == 0 && ct1 > ct2 + ct3 + 1)
verif = 1;
}
}
else
{ ct1 = fact (r, d);
for (c = 0; c <= lim; c++)
{ ct2 = fact (r - c, d);
ct3 = fact (c, d);
if (ct1 > ct2 + ct3)
ct++;
if (c == lim && r % 2 == 0 && ct1 > ct2 + ct3)
verif = 1;
}
}
if (r % 2 == 1)
ct <<= 1;
else
ct += (ct - verif);
printf ("%d\n", ct);
return 0;
}