Pagini recente » Cod sursa (job #1233862) | Cod sursa (job #1515316) | Cod sursa (job #1617824) | Cod sursa (job #282269) | Cod sursa (job #1799033)
#include <iostream>
#include <cstdio>
using namespace std;
FILE *f, *g;
int n, d;
int ap[6];
void readFile()
{
f = fopen("pascal.in", "r");
fscanf(f, "%d%d", &n, &d);
fclose(f);
}
int solve235(int d)
{
int i, rez = 0, x;
for(i = 1; i < n; i ++)
{
x = n - i + 1;
while(x % 2 == 0)
{
ap[2] ++;
x /= 2;
}
while(x % 3 == 0)
{
ap[3] ++;
x /= 3;
}
while(x % 5 == 0)
{
ap[5] ++;
x /= 5;
}
x = i;
while(x % 2 == 0)
{
ap[2] --;
x /= 2;
}
while(x % 3 == 0)
{
ap[3] --;
x /= 3;
}
while(x % 5 == 0)
{
ap[5] --;
x /= 5;
}
if(ap[d] >= 1)
rez ++;
}
return rez;
}
int solve4()
{
int i, rez = 0, x;
for(i = 1; i < n; i ++)
{
x = n - i + 1;
while(x % 2 == 0)
{
ap[2] ++;
x /= 2;
}
x = i;
while(x % 2 == 0)
{
ap[2] --;
x /= 2;
}
if(ap[2] >= 2)
rez ++;
}
return rez;
}
int solve6()
{
int i, rez = 0, x;
for(i = 1; i < n; i ++)
{
x = n - i + 1;
while(x % 2 == 0)
{
ap[2] ++;
x /= 2;
}
while(x % 3 == 0)
{
ap[3] ++;
x /= 3;
}
x = i;
while(x % 2 == 0)
{
ap[2] --;
x /= 2;
}
while(x % 3 == 0)
{
ap[3] --;
x /= 3;
}
if(ap[2] >= 1 && ap[3] >= 1)
rez ++;
}
return rez;
}
int rez;
void solve()
{
int i;
if(d == 2 || d == 3 || d == 5)
rez = solve235(d);
if(d == 4)
rez = solve4();
if(d == 6)
rez = solve6();
}
void printFile()
{
g = fopen("pascal.out", "w");
fprintf(g, "%d\n", rez);
fclose(g);
}
int main()
{
readFile();
solve();
printFile();
return 0;
}