Pagini recente » Cod sursa (job #1348666) | Cod sursa (job #2678860) | Cod sursa (job #1966975) | Cod sursa (job #2934983) | Cod sursa (job #857449)
Cod sursa(job #857449)
#include <cstdio>
#include <cassert>
using namespace std;
typedef long long int64;
const int MaxN = 22;
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 = LCM * Value[Index] / GCD(LCM, Value[Index]);
Solution += (K % 2 == 0 ? 1 : -1) * (N / LCM) * (1 << K);
Back(K + 1, Index + 1, LCM);
}
void Read() {
assert(freopen("light2.in", "r", stdin));
assert(scanf("%lld\n%d", &N, &M) == 2);
for (int i = 0; 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, 0, 1);
Print();
return 0;
}