#P16343. [科大国创杯初中组 2026] 行走
[科大国创杯初中组 2026] 行走
Background
Subtask 0 uses community testdata, and Subtask 1 uses official testdata.
Problem Description
Xiaokeke has an grid. Cell contains a positive integer . Xiaokeke wants to walk from to . He can only move down or right, that is, from to or from to . He has a positive integer , initially . Each time Xiaokeke arrives at a cell , becomes . Xiaokeke wants to know the maximum possible value of when he reaches .
denotes the greatest common divisor of positive integers and , i.e., the largest positive integer such that divides and divides .
Input Format
The input has a total of lines.
- The first line contains two positive integers .
- Lines to each contain positive integers. The -th number on line represents .
Output Format
Output one line containing one positive integer, representing the answer.
2 20
15 16
12 9
3
Hint
Sample Explanation
Xiaokeke’s optimal route is .
Other Sample Notes
- Samples 2 to 5: see
walk/walk*.inandwalk/walk*.ansin the contestant directory.
Constraints
For all data, it is guaranteed that:
- .
- .
- All input numbers are positive integers.
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| The data is guaranteed to be random | |||
| None | |||
Translated by ChatGPT 5