import math A,B,C,D,E=map(int,input().split()) ab=A+B cd=C+D L=ab*cd//math.gcd(ab,cd) p=[0]*(L+1) for i in range(L): p[i+1]=p[i]+(i%ab