Number Operating (Easy Version)
Ariana Grande - stay
This is the easy version of the problem. The difference between the versions is that in this version, the sum of over all test cases does not exceed .
You have a variable , initially equal to . In one operation, you can do one of the following:
- Operation : add to , where is the number of times Operation has been performed in a row immediately before this one (in particular, if this is the first operation or the previous operation was Operation );
- Operation : subtract from (the result may be negative).
For a non-negative integer , let be the minimum number of operations needed to make equal to . It can be shown that this is always possible.
You are given two integers and . Find . Since the answer can be very large, output it modulo .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The only line of each test case contains two integers and ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the value of modulo .
Note
In the first test case, . Initially, . One optimal sequence of operations is as follows:
- Perform Operation with , so becomes .
- Perform Operation with , so becomes .
- Perform Operation with , so becomes .
- Perform Operation , so becomes .
- Perform Operation , so becomes .
- Perform Operation , so becomes .
It can be shown that cannot be reached in or fewer operations. Thus, , and the answer is .
In the second test case, and . We have , , and . Thus, the answer is .
In the third test case, . We can perform Operation seven times in a row to reach . It can be shown that cannot be reached in or fewer operations. Thus, , and the answer is .
5 4 4 1 3 127 127 0 1000 999999999999900001 1000000000000000000
6 6 7 25383 102936941
Discussions & Comments
Share your approach or ask questions about this problem (0)
You must be logged in to comment or start a discussion on this problem.
Log InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments