# 二分探索と包除原理だな from math import lcm def check(X): divisible = 0 divisible += X//A divisible += X//B divisible -= X//AB if X-divisible1: mid = (OK+NG)//2 if check(mid)==1: OK=mid else: NG=mid print(OK)