Pagini recente » Cod sursa (job #1074376) | Cod sursa (job #1433965) | Cod sursa (job #498981) | Cod sursa (job #1137663) | Cod sursa (job #1465826)
#include <stdio.h>
int r, d, total[6];
int count = 0, i, aux;
int main()
{
FILE *in, *out;
in = fopen("pascal.in", "r");
out = fopen("pascal.out", "w");
fscanf(in, "%d %d", &r, &d);
for (i = 1; i <= r/2; i++)
{
total[2] = total[3] = total[5] = 0;
if (d == 2 || d == 4)
{
aux = r;
while(aux)
{
aux >>= 1;
total[2] += aux;
}
aux = i;
while(aux)
{
aux >>= 1;
total[2] -= aux;
}
aux = r-i;
while(aux)
{
aux >>= 1;
total[2] -= aux;
}
}
if (d == 3 || d == 6)
{
aux = r;
while(aux)
{
aux /= 3;
total[3] += aux;
}
aux = i;
while(aux)
{
aux /= 3;
total[3] -= aux;
}
aux = r-i;
while(aux)
{
aux /= 3;
total[3] -= aux;
}
}
if (d == 5)
{
aux = r;
while(aux)
{
aux /= 5;
total[5] += aux;
}
aux = i;
while(aux)
{
aux /= 5;
total[5] -= aux;
}
aux = r-i;
while(aux)
{
aux /= 5;
total[5] -= aux;
}
}
if (d == 2)
count += (total[2] ? 1 : 0);
else if (d == 3)
count += (total[3] ? 1 : 0);
else if (d == 4)
count += (total[2] >= 2 ? 1 : 0);
else if (d == 5)
count += (total[5] ? 1 : 0);
else if (d == 6)
count += (total[3] ? 1 : 0);
}
count *= 2;
if ((r/2)*2 == r)
{
if (d == 2)
count -= (total[2] ? 1 : 0);
else if (d == 3)
count -= (total[3] ? 1 : 0);
else if (d == 4)
count -= (total[2] >= 2 ? 1 : 0);
else if (d == 5)
count -= (total[5] ? 1 : 0);
else if (d == 6)
count -= (total[3] ? 1 : 0);
}
fprintf(out, "%d\n", count);
fclose(in);
fclose(out);
return 0;
}