#define _USE_MATH_DEFINES #include //cin, cout #include //vector #include //sort,min,max,count #include //string,getline, to_string #include //fixed #include //setprecision #include //swap, pair #include //abs(int) #include //sqrt,ceil,M_PI, pow, sin #include //stringstream, getline #include //gcd, accumlate #include //deque #include //randam_device #include //numeric_limits using namespace std; constexpr long long int D_MOD = 1000000007; inline long long int Greatest_Common_Divisor(long long int a, long long int b) { //aとbの最大公約数を返す while (a != 0 && b != 0) { if (a > b) { a = a - b; } else { b = b - a; } } return(a + b); } inline long long int Least_Common_Multiple(long long int gcd, long long int a, long long int b) { //aとbの最小公倍数を返す //先に最大公約数gcdが計算済である必要がある return (a * b) / gcd; } int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; int x = a + b; int y = c + d; long long int LCM = Least_Common_Multiple(Greatest_Common_Divisor(x, y), x, y); vector rob_a(x); vector rob_b(y); for (int i = 0; i < a; i++) { rob_a[i] = true; } for (int i = 0; i < c; i++) { rob_b[i] = true; } int ans = 0; if (e <= LCM) { for (int i = 0; i < e; i++) { if (rob_a[i % x] && rob_b[i % y]) { ans++; } } } else { int temp = 0; for (int i = 0; i < LCM; i++) { if (rob_a[i % x] && rob_b[i % y]) { temp++; } } ans = temp * (e / LCM); for (int i = 0; i < e % LCM; i++) { if (rob_a[i % x] && rob_b[i % y]) { ans++; } } } cout << ans << endl; return 0; }