Cod sursa(job #973040)

Utilizator Theorytheo .c Theory Data 13 iulie 2013 11:25:24
Problema Light2 Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>

using namespace std;

ifstream fin ("light2.in");
ofstream fout ("light2.out");

typedef long long int64;

int64 N; int M; int V[25];int64 Response;


void Read() {

    fin >> N >> M;
    for(int i = 1; i <= M; ++i)
        fin >> V[i];
}


inline int64 GCD(int64 A, int64 B) {

    while(B) {int64 R = A % B; A = B; B = R;}

    return A;
}


void Back(int K, int Index, int64 Value) {

    if(Index == M + 1) return;

    Back(K, Index + 1, Value);
    Value = Value * V[Index] / GCD(Value, V[Index]);
    Response += (((K & 1) == 0) ? 1 : -1) * (N / Value) * (1 << K);
    Back(K + 1, Index + 1, Value);
}


void Print() {

    fout << Response <<'\n';
}


int main() {

    Read (); Back(0, 1, 1); Print ();

    return 0;
}