Cod sursa(job #1747367)

Utilizator antanaAntonia Boca antana Data 24 august 2016 20:17:51
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <cstdio>

int v[5];

int main()
{
    freopen("pascal.in", "r", stdin);
    freopen("pascal.out", "w", stdout);

    int i, ans=0, n, d, lim, x;

    scanf("%d%d", &n, &d);

    lim=n/2;
    for(i=1;i<=lim;++i)
    {
        x=n-i+1;
        while(!(x%2)) x/=2, ++v[2];
        while(!(x%3)) x/=3, ++v[3];
        while(!(x%5)) x/=5, ++v[5];

        x=i;
        while(!(x%2)) x/=2, --v[2];
        while(!(x%3)) x/=3, --v[3];
        while(!(x%5)) x/=5, --v[5];

        if(d==6 && v[2] > 0 && v[3] > 0) ans+=2;
        if(d==4 && v[2] > 1) ans+=2;
        if((d==3 || d==2 || d==5) && v[d] > 0) ans+=2;
    }
    if(n%2==0){
        if(d==6 && v[2] > 0 && v[3] > 0) ans--;
        if(d==4 && v[2] > 1) ans--;
        if((d==3 || d==2 || d==5) && v[d] > 0) ans--;
    }

    printf("%d", ans);

    return 0;
}