Power Tiller
Time limit3sMemory limit256 MB
Count distinct positions reachable by steps of lengths 1, 2, 4 and so on moving only right or up inside an A by B rectangle.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Yeondol has taken Sesun's power tiller out onto the coordinate plane. He drives badly, so he moves only by these two rules.
- Every move points either in the positive x direction or in the positive y direction.
- The -th move covers exactly cells in the chosen direction.
The plane Yeondol drives on is the rectangle with corners , , and , and the boundary belongs to the rectangle. Yeondol starts at and never makes a move that would take him outside the rectangle. He may repeat moves as many times as he likes, or make none at all.
Counting the starting point and the position after each completed move, how many distinct coordinates can Yeondol visit?
Input
The first line contains the number of test cases ().
Each of the next lines contains two integers and () separated by a space.
Output
For each test case, print on its own line how many distinct coordinates Yeondol can visit.