Cod sursa(job #1821625)

Utilizator medicinedoctoralexandru medicinedoctor Data 3 decembrie 2016 13:35:26
Problema Pascal Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>

using namespace std;

int n,d,c=0,x2=0,x3=0,x5=0;

void adun()
{
    if (d==2 && x2>0) c++;
    if (d==3 && x3>0) c++;
    if (d==4 && x2>1) c++;
    if (d==5 && x5>0) c++;
    if (d==6 && x2>0 && x3>0) c++;
}

void calc()
{
    //for (int x,i=1; i<=n; i++)
    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;
        }
        adun(); if ((n % 2==1) || (i!=n/2 && n % 2== 0)) adun();
    }
}

main()
{
    ifstream fin("pascal.in");
    fin >> n >> d;
    fin.close();
    calc();
    ofstream fout("pascal.out");
    fout << c;
    fout.close();
}