Cod sursa(job #447074)

Utilizator SpiderManSimoiu Robert SpiderMan Data 27 aprilie 2010 17:14:35
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>

int N, D, p[70], x, K, rez;

void solve()
{
    x = N - K;
    while (x % 2 == 0)
        x /= 2, p[2]++;
    while (x % 3 == 0)
        x /= 3, p[3]++;
    while (x % 5 == 0)
        x /= 5, p[5]++;
    x = K + 1;
    while (x % 2 == 0)
        x /= 2, p[2]--;
    while (x % 3 == 0)
        x /= 3, p[3]--;
    while (x % 5 == 0)
        x /= 5, p[5]--;

    if (D == 2)
        rez += (p[2] >= 1);
    if (D == 3)
        rez += (p[3] >= 1);
    if (D == 4)
        rez += (p[2] >= 2);
    if (D == 5)
        rez += (p[5] >= 1);
    if (D == 6)
        rez += (p[2] >= 1 && p[3] >= 1);
}

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

    scanf("%d%d", &N, &D);

    for (K = 0; K < ((N + 1) >> 1) - 1; K++)
        solve();
    rez *= 2;
    if (N % 2 == 0)
        solve();

    printf("%d\n", rez);

    return 0;
}