Cod sursa(job #857445)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 17 ianuarie 2013 20:37:39
Problema Light2 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>
#include <cassert>

using namespace std;

typedef long long int64;

const int MaxN = 25;

int M, Value[MaxN];
int64 N, Solution;

int64 GCD(const int64 X, const int64 Y) {
    if (Y == 0)
        return X;
    return GCD(Y, X % Y);
}

void Back(const int K, const int Index, int64 LCM) {
    if (Index > M)
        return;
    Back(K, Index + 1, LCM);
    LCM = Value[Index] * LCM / GCD(Value[Index], LCM);
    Solution += (K % 2 == 0 ? 1 : -1) * (1 << K) * N / LCM;
    Back(K + 1, Index + 1, LCM);
}

void Solve() {

}

void Read() {
    assert(freopen("light2.in", "r", stdin));
    assert(scanf("%lld\n%d", &N, &M) == 2);
    for (int i = 1; i <= M; ++i)
        assert(scanf("%d", &Value[i]) == 1);
}

void Print() {
    assert(freopen("light2.out", "w", stdout));
    printf("%lld\n", Solution);
}

int main() {
    Read();
    Back(0, 1, 1);
    Print();
    return 0;
}