-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy path148A - Insomnia cure.cpp
57 lines (51 loc) · 1.11 KB
/
148A - Insomnia cure.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
//4007107 Jul 3, 2013 7:04:01 PM fuwutu 148A - Insomnia cure GNU C++0x Accepted 15 ms 0 KB
#include <iostream>
using namespace std;
int LCM(int m, int n)
{
int mm(m), nn(n), r;
while ((r = m % n) != 0)
{
m = n;
n = r;
}
return mm / n * nn;
}
int main()
{
int k, l, m, n, d, count(0);
cin >> k >> l >> m >> n >> d;
int lcm = LCM(LCM(k, l), LCM(m, n));
if (d > lcm)
{
int r = 0;
for (int i = 1; i <= d % lcm; ++i)
{
if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0)
{
r += 1;
}
}
int c = r;
for (int i = d % lcm + 1; i <= lcm; ++i)
{
if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0)
{
c += 1;
}
}
count = c * (d / lcm) + r;
}
else
{
for (int i = 1; i <= d; ++i)
{
if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0)
{
count += 1;
}
}
}
cout << count << endl;
return 0;
}