题解建议看这个:https://www.acwing.com/solution/content/29702/
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 20;
int p[N];
int main() {
int n, m;
cin >> n >> m;
int res = 0;
for (int i = 0; i < m; i++)cin >> p[i];
for (int i = 1; i < 1 << m; i++) {
int t = 1;
int s = 0;
for (int j = 0; j < m; j++) {
if (i >> j & 1) {
if ((LL)t * p[j] > n) {
t = -1;
break;
}
t *= p[j];
s++;
}
}
if(t==-1)continue;
if (s % 2 == 1)res += n / t;
else res -= n / t;
}
cout << res << endl;
return 0;
}