#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { ll a, b, c, d, e, lcm, cnt1 = 0, cnt2 = 0, coin = 0, ans, r; cin >> a >> b >> c >> d >> e; bool x = true, y = true; lcm = (a+b)*(c+d)/gcd(a+b, c+d); for (int i = 0; i < lcm; i++){ cnt1++; cnt2++; if (x && y) coin++; if (x && cnt1 == a){ x = false; cnt1 = 0; } else if (!x && cnt1 == b){ x = true; cnt1 = 0; } if (y && cnt2 == c){ y = false; cnt2 = 0; } else if (!y && cnt2 == d){ y = true; cnt2 = 0; } } coin *= e/lcm; r = e%lcm; for (int i = 0; i < r; i++){ cnt1++; cnt2++; if (x && y) coin++; if (x && cnt1 == a){ x = false; cnt1 = 0; } else if (!x && cnt1 == b){ x = true; cnt1 = 0; } if (y && cnt2 == c){ y = false; cnt2 = 0; } else if (!y && cnt2 == d){ y = true; cnt2 = 0; } } cout << coin << endl; }