import sys from heapq import heappop, heappush from math import gcd input = sys.stdin.buffer.readline a, b, c, d, e = map(int, input().split()) g = gcd(a + b, c + d) lcm = (a + b) * (c + d) // g temp = 0 events = [] while temp < lcm: heappush(events, (temp, 1)) heappush(events, (temp + a, -1)) temp += a + b temp = 0 while temp < lcm: heappush(events, (temp, 2)) heappush(events, (temp + c, -2)) temp += c + d # print("events1", events) score_cycle = 0 flag1 = 0 flag2 = 0 now = 0 onflag = 0 while events: temp, num = heappop(events) # print("tn", temp, num) if num == 1: flag1 = 1 elif num == 2: flag2 = 1 elif num == -1: flag1 = 0 else: flag2 = 0 if flag1 == 1 and flag2 == 1: onflag = 1 now = temp elif flag1 == 0: if onflag: score_cycle += temp - now onflag = 0 elif flag2 == 0: if onflag: score_cycle += temp - now onflag = 0 events = [] lim = e % lcm temp = 0 while temp < lim: heappush(events, (temp, 1)) temp += a if temp >= lim: break heappush(events, (temp, -1)) temp += b temp = 0 while temp < lim: heappush(events, (temp, 2)) temp += c if temp >= lim: break heappush(events, (temp, -2)) temp += d # print("events2", events) score_rem = 0 flag1 = 0 flag2 = 0 now = 0 onflag = 0 while events: temp, num = heappop(events) if num == 1: flag1 = 1 elif num == 2: flag2 = 1 elif num == -1: flag1 = 0 else: flag2 = 0 if flag1 == 1 and flag2 == 1: onflag = 1 now = temp elif flag1 == 0: if onflag: score_rem += temp - now onflag = 0 elif flag2 == 0: if onflag: score_rem += temp - now onflag = 0 ans = (e // lcm) * score_cycle + score_rem print(ans)