Kangaroo Race
시간 제한5초메모리 제한1024 MB
길이 n인 순환 트랙에서 y번 칸에 있는 캥거루가 한 번에 y(y-1)칸씩 앞으로 뛸 때, 1번 칸에 도달하는 최소 점프 횟수를 구하거나 불가능을 판정한다.
문제
The country of Austria is well known for their kangaroo population. In order to stay in good shape, the kangaroos each have an athletics track to practice for the Annual Austrian Pogostick Jumping Event.
Each athletics track consists of segments, each meter in length. These segments are numbered from to , in order. The track is cyclic, so after segment follows segment again.
On each track, a kangaroo is located in one of the segments. The kangaroo can make some finite number of jumps. In each jump, if the kangaroo is currently in segment , it will jump segments ahead. Your task is to determine the minimum number of jumps needed for the kangaroo to reach the segment numbered .
Since the kangaroo population in Austria is quite large, you are asked to solve this problem for many different kangaroos on different athletics tracks.
입력
The input consists of:
- One line with an integer (), the number of kangaroos.
- lines with two integers and (), the number of segments in one of the athletics tracks and the kangaroo's initial position on this track.
출력
For each kangaroo, if the kangaroo can reach can reach the segment numbered in a finite number of jumps, output the minimum number of jumps needed. Otherwise, output "impossible".
힌트
The intermediate values of your calculation may become larger than what fits in -bit integers. To store these large intermediate values, use __int128 in C++ or java.math.BigInteger in Java/Kotlin. In Python, integers have arbitrary size by default.