Kangaroo Race

시간 제한5초메모리 제한1024 MB

요약
길이 n인 순환 트랙에서 y번 칸에 있는 캥거루가 한 번에 y(y-1)칸씩 앞으로 뛸 때, 1번 칸에 도달하는 최소 점프 횟수를 구하거나 불가능을 판정한다.
난이도

어려움10점 중 8점

유형
정수론, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 nn segments, each 11 meter in length. These segments are numbered from 11 to nn, in order. The track is cyclic, so after segment nn follows segment 11 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 yy, it will jump y(y−1)y(y-1) segments ahead. Your task is to determine the minimum number of jumps needed for the kangaroo to reach the segment numbered 11.

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 kk (1≤k≤1051\leq k\leq 10^5), the number of kangaroos.
  • kk lines with two integers nn and xx (1≤x≤n≤10181\leq x \leq n \leq 10^{18}), 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 11 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 6464-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.

예제1

  1. 예제 1

    입력
    4
    5 2
    6 2
    8 3
    12345678910 1
    
    예상 출력
    2
    impossible
    1
    0