joj 2431: Shift and Increment
2431: Shift and Increment
Result
TIME Limit
MEMORY Limit
Run Times
AC Times
JUDGE
5s
16384K
1362
215
Standard
Shift and increment is the basic operations of the ALU (Arithmetic Logical Unit) in CPU. One number can be transform to any other number by these operations. Your task is to find the shortest way from x to 0 using the shift (*=2) and increment (+=1) operations. All operations are restricted in 0..n, that is if the result x is greater than n, it should be replace as x%n.
Input and Output
There are two integer x, n (n <=1000000)
Sample Input
2 4
3 9
Sample Output
1
3
Problem Source: provided by skywind
#include