forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10325.cpp
80 lines (76 loc) · 951 Bytes
/
10325.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
typedef long long ss;
vector<ss> lt;
int N, M;
ss A[20], Sum;
ss gcd(ss a, ss b)
{
return b ? gcd(b, a % b) : a;
}
ss Count(ss limit)
{
ss i, lcm = A[1], gd, pro;
for (i = 2; i <= limit; i++)
{
gd = gcd(lcm, A[i]);
pro = lcm * A[i];
lcm = pro / gd;
}
return N / lcm;
}
ss Recur(ss n, ss level, ss limit)
{
ss i;
if (level >= 0)
{
A[level] = lt[n];
}
if (level == limit)
{
if (limit % 2)
{
Sum += Count(limit);
}
else
{
Sum -= Count(limit);
}
return 0;
}
for (i = n + 1; i < M; i++)
{
Recur(i, level + 1, limit);
}
return 0;
}
void Cal()
{
int i, j;
Sum = 0;
for (i = 0; i < M; i++)
{
Sum += N / lt[i];
}
for (i = 2; i <= M; i++)
{
Recur(-1, 0, i);
}
j = N - Sum;
cout << j << endl;
}
int main()
{
int i, n;
while (cin >> N >> M)
{
for (i = 0; i < M; i++)
{
cin >> n;
lt.push_back(n);
}
Cal();
lt.clear();
}
return 0;
}