CF BUDDY
← Problems·

1352C · K-th Not Divisible by n

1200 · binary search, math

Problem: You are given two positive integers nn and kk. Print the kk-th positive integer that is not divisible by nn.

For example, if n=3n=3, and k=7k=7, then all numbers that are not divisible by 33 are: 1,2,4,5,7,8,10,11,131, 2, 4, 5, 7, 8, 10, 11, 13 \dots. The 77-th number among them is 1010.

Input Format: The first line contains an integer tt (1t10001 \le t \le 1000) — the number of test cases in the input. Next, tt test cases are given, one per line.

Each test case is two positive integers nn (2n1092 \le n \le 10^9) and kk (1k1091 \le k \le 10^9).

Output Format: For each test case print the kk-th positive integer that is not divisible by nn.

Sample Cases

Case 1

Input

6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1

Output

10
15
1999999999
113
1000000001
1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback