'commit'
This commit is contained in:
44
TangDou/AcWing/Math/RongChi/HDU1796.cpp
Normal file
44
TangDou/AcWing/Math/RongChi/HDU1796.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user