-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeMultiples.cpp
More file actions
56 lines (47 loc) · 812 Bytes
/
Copy pathPrimeMultiples.cpp
File metadata and controls
56 lines (47 loc) · 812 Bytes
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define int __int128_t
typedef long long ll;
ll n, k;
const ll Sz = 20;
ll a[Sz + 1];
ll d[Sz + 1];
ll res = 0;
void xulikq()
{
int tmp = 1;
ll Cnt = 0;
for(ll i = 1; i <= k; i++)
{
if(d[i])
{
tmp *= a[i];
Cnt++;
if(tmp > n) return;
}
}
if(Cnt == 0) return;
if(Cnt % 2 != 0) res += (n / tmp);
else res -= (n / tmp);
}
void duyet(ll x)
{
if(x > k) xulikq();
else
{
for(ll i = 0; i <= 1; i++)
{
d[x] = i;
duyet(x + 1);
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(ll i = 1; i <= k; i++) cin >> a[i];
duyet(1);
cout << res;
}