problem nowcoder
真没想到这题用容斥原理来做,感觉很新颖
这种求区间[l,r]的问题若用[1,r]-[1,l-1],记得把 l-1
// Decline is inevitable,
// Romance will last forever.
#include <bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define LL long long
#define ld long double
#define endl '\n'
#define RE0 return 0
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define mod(a, b) a < b ? a : a % b + b
#define int long long
const int maxn = 20 + 10;
const int P = 998244353; //998244353
const int INF = 0x7f7f7f7f;
int n;
int a[maxn];
int l, r, k;
int cnt[110];
int vis[110];
void solve() {
cin >> l >> r >> k;
l--;
int sum = 0;
for(int i = 1; i <= k; i++) cin >> a[i];
for(int i = 1; i <(1<<k); i++) {
int cnt = 0;
int t = 1;
for(int j = 0; j < k; j++) {
if(i&(1<<j)) {
cnt++;
t *= a[j + 1];
if(t > r) break;
}
}
if(cnt & 1) sum += r / t - l / t;
else sum -= r/t - l/t;
}
cout << r - l - sum << endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// int T; scanf("%d", &T); while(T--)
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
// int T; cin >> T; while(T--)
solve();
RE0;
}