eolymp
bolt
Try our new interface for solving problems
Problems

n-th term divisible by a, b or c

n-th term divisible by a, b or c

Given three integers $a, b$ and $c$. Find the $n$-th term which is divisible by either of $a, b$ or $c$. \InputFile Four integers $a, b, c$ and $n~(a, b, c, n \le 10^9)$. \OutputFile Print the $n$-th term divisible by either $a$ or $b$ or $c$. It is known that the answer is no more than $10^9$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
2 3 5 10
Output example #1
14
Input example #2
3 5 7 10
Output example #2
18
Input example #7
33 45 37 13000
Output example #7
170676