codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

476A.md (1120B)


      1 Source: https://codeforces.com/problemset/problem/476/A
      2 
      3 A. Dreamoon and Stairs
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
     22 
     23 What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
     24 
     25 Input
     26 
     27 The single line contains two space separated integers *n*, *m* (0 < *n* ≤ 10000, 1 < *m* ≤ 10).
     28 
     29 Output
     30 
     31 Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print  - 1 instead.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 10 2
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 6
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 3 5
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 -1
     57 ```
     58 
     59 Note
     60 
     61 For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
     62 
     63 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.