#P9552. 「CROI · R1」浣熊的小溪
「CROI · R1」浣熊的小溪
Background
"Coming from the sun, and walking into the sunlight; spreading bear paws, embracing the wind, yet at farewell, lowering the head to sing to oneself."
That playful growth by the Dream Maple shore, that unrestrained belief under the sun, has grown stronger with time, echoing in the hearts of countless raccoons.
Sadly, along the upper Ling Stream, one person’s will and various constructions have torn apart the innocent years, carving a lonely barrier.
That clear little stream, those happy days of the past—will they still make one stop in remembrance...
Problem Description
The forest of Raccoon Ridge can be viewed as an grid. Wastewater discharged by a factory has polluted the Dream Maple Stream (a straight line) that runs through the forest, making the regions it passes through harmful to raccoons. The little raccoon CleverRaccoon, in order to study the harm caused by the wastewater, seeks your help.
Let denote the maximum number of cells that a straight line can pass through in an grid.
The little raccoon has two kinds of questions to ask you:
- Given , find .
- Given , you need to find such that , and is as small as possible. Output the minimum value of modulo . The testdata guarantees that .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , indicating that there are queries.
For each query:
The first line contains a positive integer , indicating the type of the question.
The second line: if , input positive integers and ; if , input positive integers , , and .
Output Format
Output lines. For each query, output one positive integer on a single line, representing the answer to the corresponding question.
2
1
2 3
2
2 3 10
4
12
Hint
Sample Explanation #1
For the first query:
The situation shown in the figure below is an optimal construction. When the Dream Maple Stream passes through a grid forest, it can pass through at most small cells (the yellow parts are the cells it passes through, and the gray parts are the cells it does not pass through).

The construction below is not optimal. The Dream Maple Stream passes through a vertex between two green cells, so neither of the two green regions is counted as being passed through. Therefore, the Dream Maple Stream passes through only small cells.

For the second query:
As shown in the figure below, only when , can the added number of cells be minimized while making the Dream Maple Stream pass through cells (the left side of the red dashed line is the original forest, and the right side is the added part).

Constraints
This problem uses bundled Subtask testdata.
| Subtask | Special Property | Score | |||
|---|---|---|---|---|---|
| No special property | |||||
For of the data, it is guaranteed that , , , .
Translated by ChatGPT 5