Pagini recente » Cod sursa (job #1632144) | Cod sursa (job #978284) | Cod sursa (job #2559648) | Cod sursa (job #1499779) | Cod sursa (job #2070607)
#include <fstream>
using namespace std;
ifstream fin("light2.in");
ofstream fout("light2.out");
#define ll long long
ll ans = 0, lim;
int n, a[22];
inline ll gcd(ll a, ll b) {
ll r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
void bkt(int p, ll s, int cnt, bool x) {
if (s > lim) return ;
else if (p == n) {
if (x) ans += (cnt / 2) * (lim / s);
else ans -= (cnt / 2) * (lim / s);
} else {
bkt(p + 1, s, cnt, x);
bkt(p + 1, s * a[p] / gcd(s, a[p]), cnt * 2, 1 ^ x);
}
}
int main() {
fin >> lim >> n;
for (int i = 0; i < n; i++) fin >> a[i];
bkt(0, 1, 1, 0);
fout << ans;
return 0;
}