from math import gcd a, b, c, d, e = map(int, input().split()) f = (a+b)*(c+d)//gcd(a+b, c+d) mk = f//(a+b) ff = lambda k:(k*(a+b))%(c+d) if (k*(a+b))%(c+d) else c+d R = 0 xx = e%f//(a+b) rr = 0 fl=0 for k in range(mk): nokori = min(max(c-ff(k), 0), a) if a-(c+d-ff(k)) >=0: ek, fk = divmod(a-(c+d-ff(k)), c+d) r = min(fk,c)+ek*c + nokori else: r = nokori if k==xx: ta = min(a, e%(a+b)) nokori = min(max(c-ff(k), 0), ta) if ta-(c+d-ff(k)) >=0: ek, fk = divmod(ta-(c+d-ff(k)), c+d) rr += min(fk,c)+ek*c + nokori else: rr += max(0, nokori) fl = 1 if not fl: rr += r # print("xx",r) R += r # print(mk, r, rr) #print(R, rr, e//f) print(R*(e//f)+rr)