Cod sursa(job #827322)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 1 decembrie 2012 22:52:16
Problema Pascal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <cstdio>

using namespace std;

int Row, Factor[3] = {2, 3, 5}, Power[3], Solution;

inline int GetPower(int Factorial, int X) {
    int power = 0, Y = X;
    for (int p = 1; Y <= Factorial; ++p, Y *= X)
        power += Factorial / Y;
    return power;
}

inline int IsDivisible(int n, int k) {
    int divisible = 1;
    for (int i = 0; i < 3; ++i)
        divisible &= (GetPower(n, Factor[i]) - GetPower(k, Factor[i]) - GetPower(n - k, Factor[i]) >= Power[i]);
    return divisible;
}

void Solve() {
    int n = Row;
    for (int k = 1; k < n / 2; ++k)
        Solution += IsDivisible(n, k);
    Solution *= 2;
    if (n % 2 == 0)
        Solution += IsDivisible(n, n / 2);
}

void Read() {
    freopen("pascal.in", "r", stdin);
    int D; scanf("%d %d", &Row, &D);
    for (int i = 0; i < 3; ++i)
        for (; D % Factor[i] == 0; ++Power[i], D /= Factor[i]);
}

void Print() {
    freopen("pascal.out", "w", stdout);
    printf("%d\n", Solution);
}

int main() {
    Read();
    Solve();
    Print();
    return 0;
}