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
The result of integer division $a~\mathrm{div}~b$ is equal to the largest integer $c$ such that $b \cdot c \leq a$ . $a$ modulo $b$ (shortened $a \bmod b$ ) is the only integer $c$ such that $0 \leq c < b$ , and $a - c$ is divisible by $b$ .
In the first sample, $11~\mathrm{div}~3 = 3$ and $11 \bmod 3 = 2$ . Since $3 \cdot 2 = 6$ , then $x = 11$ is a solution to $(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6$ . One can see that $19$ is the only other positive integer solution, hence $11$ is the smallest one.
In the first sample, $11~\mathrm{div}~3 = 3$ and $11 \bmod 3 = 2$ . Since $3 \cdot 2 = 6$ , then $x = 11$ is a solution to $(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6$ . One can see that $19$ is the only other positive integer solution, hence $11$ is the smallest one.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted