CF BUDDY
← Problems·

1085B · Div Times Mod

1100 · math

Problem: Vasya likes to solve equations. Today he wants to solve (x div k)(xmodk)=n(x~\mathrm{div}~k) \cdot (x \bmod k) = n, where div\mathrm{div} and mod\mathrm{mod} stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, kk and nn are positive integer parameters, and xx is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible xx. Can you help him?

Input Format: The first line contains two integers nn and kk (1n1061 \leq n \leq 10^6, 2k10002 \leq k \leq 1000).

Output Format: Print a single integer xx — the smallest positive integer solution to (x div k)(xmodk)=n(x~\mathrm{div}~k) \cdot (x \bmod k) = n. It is guaranteed that this equation has at least one positive integer solution.

Note: The result of integer division a div ba~\mathrm{div}~b is equal to the largest integer cc such that bcab \cdot c \leq a. aa modulo bb (shortened amodba \bmod b) is the only integer cc such that 0c<b0 \leq c < b, and aca - c is divisible by bb.

In the first sample, 11 div 3=311~\mathrm{div}~3 = 3 and 11mod3=211 \bmod 3 = 2. Since 32=63 \cdot 2 = 6, then x=11x = 11 is a solution to (x div 3)(xmod3)=6(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6. One can see that 1919 is the only other positive integer solution, hence 1111 is the smallest one.

Sample Cases

Case 1

Input

6 3

Output

11

Case 2

Input

1 2

Output

3

Case 3

Input

4 6

Output

10

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback