#P4893. Dreamoon and Stairs

Dreamoon and Stairs

Dreamoon and Stairs

题面翻译

题面 DM小朋友想要上一个有 nn 级台阶的楼梯。他每一步可以上 1122 级台阶。假设他走上这个台阶一共用了 xx 步。现在DM想知道 xx 是否可能为 mm 的倍数。如果可能,输出 xx 的最小值。如果不可能,输出 1-1 输入 两个正整数 n,m  (n<=10000,m<=10)n,m\ \ (n<=10000,m<=10) 输出 按要求输出 xx1-1

感谢@FCBM71 提供的翻译

题目描述

Dreamoon wants to climb up a stair of n n steps. He can climb 1 1 or 2 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m m .

What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?

输入格式

The single line contains two space separated integers n n , m m ( 0<n<=10000,1<m<=10 0<n<=10000,1<m<=10 ).

输出格式

Print a single integer — the minimal number of moves being a multiple of m m . If there is no way he can climb satisfying condition print 1 -1 instead.

样例 #1

样例输入 #1

10 2

样例输出 #1

6

样例 #2

样例输入 #2

3 5

样例输出 #2

-1

提示

For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.

For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.