1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include<iostream>
using namespace std;
typedef long long LL;
const int N = 20;
int p[N];
int main() { int n, m; cin >> n >> m; for(int i = 0; i < m; i ++) cin >> p[i]; LL res = 0; for(int i = 1; i < 1 << m; i ++) { LL t = 1, cnt = 0; for(int j = 0; j < m; j ++) if(i >> j & 1) { cnt ++; if(t * p[j] > n) { t = -1; break; } t *= p[j]; } if(t != -1) { if(cnt % 2) res += n / t; else res -= n / t; } } cout << res << endl; return 0; }
|