题库练习 Div Times Mod
← 上一题 下一题 →

A12183 | Div Times Mod

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

输入格式

The first line contains two integers $n$ and $k$ ( $1 \leq n \leq 10^6$ , $2 \leq k \leq 1000$ ).

输出格式

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

输入输出样例

输入 #1
6 3
输出 #1
11
输入 #2
1 2
输出 #2
3
输入 #3
4 6
输出 #3
10
C++ 编辑器
输入
输出