欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1607B.Odd Grasshopper
Odd Grasshopper
The grasshopper is located on the numeric axis at the point with coordinate .
Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate with a distance to the left moves the grasshopper to a point with a coordinate , while jumping to the right moves him to a point with a coordinate .
The grasshopper is very fond of positive integers, so for each integer starting with the following holds: exactly minutes after the start he makes a jump with a distance of exactly . So, in the first minutes he jumps by , then by , and so on.
The direction of a jump is determined as follows: if the point where the grasshopper was before the jump has an even coordinate, the grasshopper jumps to the left, otherwise he jumps to the right.
For example, if after consecutive jumps he arrives at the point with a coordinate , he will jump by a distance of to the right, since is an odd number, and will end up at a point . Since is an even number, the next jump the grasshopper will make to the left by a distance of , and it will move him to the point .
Find exactly which point the grasshopper will be at after exactly jumps.
Input
The first line of input contains an integer () — the number of test cases.
Each of the following lines contains two integers () and () — the coordinate of the grasshopper's initial position and the number of jumps.
Output
Print exactly lines. On the -th line print one integer — the answer to the -th test case — the coordinate of the point the grasshopper will be at after making jumps from the point .
Note
The first two test cases in the example correspond to the first two jumps from the point .
Since is an even number, the first jump of length is made to the left, and the grasshopper ends up at the point .
Then, since is an odd number, a jump of length is made to the right, bringing the grasshopper to the point with coordinate .
Samples
9
0 1
0 2
10 10
10 99
177 13
10000000000 987654321
-433494437 87178291199
1 0
-1 1
-1
1
11
110
190
9012345679
-87611785637
1
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |