atcoder#AGC057D. [AGC057D] Sum Avoidance
[AGC057D] Sum Avoidance
Score : points
Problem Statement
You are given positive integers and . A sequence of positive integers is said to be a good sequence when satisfying the following two conditions.
- holds.
- holds for any sequence of non-negative integers .
Let be the lexicographically smallest of the good sequences with the maximum number of terms. Print the -th term of this sequence, or -1
if .
We will give you test cases; solve each of them.
Constraints
Input
Input is given from Standard Input in the following format:
Each case is in the following format:
Output
Print lines. The -th line should contain the answer for .
13
3 1
3 2
7 1
7 2
7 3
7 4
10 1
10 2
10 3
10 4
10 5
2022 507
1000000000000000000 999999999999999999
2
-1
2
4
6
-1
3
6
8
9
-1
1351
-1
For the cases , the sequence will be as follows.
- For : .
- For : .
- For : .