Files
python/TangDou/AcWing/Math/RongChi/HDU1796.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

44 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 15;
vector<int> p;
// 最小公倍数
int lcm(int a, int b) {
return a * b / __gcd(a, b);
}
signed main() {
int n, m;
while (cin >> m >> n) { // n个数,求[1~m)中有多少个数能被整除集合中的数字整除
m--; // small than m 注意细节
p.clear(); // 多组测试数据,注意清0
for (int i = 0; i < n; i++) { // n个数字组成的序列
int x;
cin >> x;
if (x) p.push_back(x); // 排除掉数字0,0不能做除数
}
int s = 0;
for (int i = 1; i < (1 << p.size()); i++) {
int cnt = 0;
int t = 1;
for (int j = 0; j < p.size(); j++) {
if (i >> j & 1) {
cnt++;
t = lcm(t, p[j]); // 这里不是简单的相乘,而是求的最小公倍数
}
}
if (cnt & 1)
s += m / t;
else
s -= m / t;
}
cout << s << endl;
}
}