Cod sursa(job #1821634)

Utilizator medicinedoctoralexandru medicinedoctor Data 3 decembrie 2016 13:42:33
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#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();
}