|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||256 MB||12||6||6||50.000%|
You are always doing impressive card tricks, and it’s driving everyone mad. To put a stop to this, your dad decides to challenge you to do a trick he thinks is impossible.
He starts by blindfolding you, and gives you a deck of N cards. He tells you that K of the cards are face up. Your task is to find a sequence of operations to perform, with the following goal: The deck should be separated into two decks at the end of the sequence, such that each of the two decks have the same number of face up cards (not necessarily K), no matter which order the cards were in initially. The other deck is initially empty. You are allowed to do the following two operations in any order, any number of times:
In order to impress your dad, you have decided not only to accept the challenge, but to find the shortest sequence of operations possible. Being a prominent programmer, you realize that you can cheat by writing a program that generates this for you.
The first line of the input consists of a single integer, T, the number of test cases. Each of the following T test cases consists of a single line with two integers, N and K, separated by a space.
For each test case, output the minimum number of operations needed to achieve the goal. If it is not possible, output -1 instead.
3 2 1 3 2 10 3
2 3 6