Pagini recente » Cod sursa (job #1099790) | Cod sursa (job #932141) | Cod sursa (job #1743057) | Cod sursa (job #2663069) | Cod sursa (job #1821634)
#include <fstream>
using namespace std;
int n,d,c=0,x2=0,x3=0,x5=0;
int adun(int x)
{
if (d==2 && x2>0) return x+1;
if (d==3 && x3>0) return x+1;
if (d==4 && x2>1) return x+1;
if (d==5 && x5>0) return x+1;
if (d==6 && x2*x3>0) return x+1;
return x;
}
void calc()
{
for (int x,i=1; i<=n/2; i++)
{
x=n-i+1;
while (x % 2 == 0)
{
x2++;
x/=2;
}
while (x % 3 == 0)
{
x3++;
x/=3;
}
while (x % 5 == 0)
{
x5++;
x/=5;
}
x=i;
while (x % 2 == 0)
{
x2--;
x/=2;
}
while (x % 3 == 0)
{
x3--;
x/=3;
}
while (x % 5 == 0)
{
x5--;
x/=5;
}
c=adun(c); if ((n % 2==1) || (i!=n/2 && n % 2== 0)) c=adun(c);
}
}
main()
{
ifstream fin("pascal.in");
fin >> n >> d;
fin.close();
calc();
ofstream fout("pascal.out");
fout << c;
fout.close();
}