35 lines
754 B
C++
35 lines
754 B
C++
// Prime Multiples
|
|
|
|
#include<bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
using ll = long long;
|
|
|
|
int main() {
|
|
ll n, k;
|
|
cin >> n >> k;
|
|
vector<ll> primes(k);
|
|
for (auto &e: primes) cin >> e;
|
|
|
|
ll ans = 0;
|
|
for (ll i = 1; i < (1 << k); i++) {
|
|
ll prime_product = 1;
|
|
for (ll j = 0; j < k; j++) {
|
|
if ( i & (1 << j)) {
|
|
if (prime_product > n / primes[j]) {
|
|
prime_product = n + 1;
|
|
break;
|
|
}
|
|
prime_product *= primes[j];
|
|
}
|
|
}
|
|
if (__builtin_popcount(i) & 1) {
|
|
ans += n / prime_product;
|
|
} else {
|
|
ans -= n / prime_product;
|
|
}
|
|
}
|
|
cout << ans << endl;
|
|
return 0;
|
|
}
|