/* -*- coding: utf-8 -*- * * 1486.cc: No.1486 ロボット - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_L = 1000 * 1000; /* typedef */ /* global variables */ int used[MAX_L + 1]; /* subroutines */ template T gcd(T m, T n) { // m > 0, n > 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } template T lcm(T m, T n) { return m * n / gcd(m, n); } /* main */ int main() { int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); int x = a + b, y = c + d; int l = lcm(x, y); for (int i = 0; i < l; i++) used[i + 1] = used[i] + ((i % x < a && i % y < c) ? 1 : 0); printf("%d\n", (e / l) * used[l] + used[e % l]); return 0; }