| SMU ICPC Selection Contest 2026 |
|---|
| Закончено |
Once upon a time, Billy had an array $$$a$$$ of length $$$n$$$ such that $$$a_i = i$$$ for all $$$1\leq i \leq n$$$, and an integer $$$m$$$ ($$$m \gt n$$$). The array $$$a$$$ was then cyclically shifted to the right by $$$k$$$ positions to form the array $$$b$$$.
For example, when $$$n= 5$$$ and $$$k = 2$$$, the arrays $$$a$$$ and $$$b$$$ are given as follows: $$$$$$ a = [1,2,3,4,5] \longrightarrow \text{cyclic right-shift by 2} \longrightarrow b=[4,5,1,2,3] $$$$$$
Billy may perform one type of operation on array $$$b$$$, consisting of two steps:
Billy especially loves arrays in which every element is $$$0$$$. Help Billy find the minimum number of operations required to transform $$$b$$$ into $$$[0, 0,\cdots, 0]$$$.
The first line contains an integer $$$t$$$ ($$$1\leq t \leq 2\times 10^5$$$), the number of test cases.
Each test case consists of a single line containing three integers $$$n, k, m$$$ ($$$1\leq n \lt m \leq 10^9$$$, $$$0 \leq k \leq n-1$$$), denoting the size of the array $$$b$$$, the right-shift offset $$$k$$$ and the modulus $$$m$$$.
$$$t$$$ lines, the answer to each test case on a single line.
21 0 35 2 6
2 6
There are $$$2$$$ test cases.
In the first test case, $$$a = [1]$$$ and since $$$k = 0$$$, $$$b = a = [1]$$$. Let $$$f(l,r)$$$ denote one application of the operation to the subarray from index $$$l$$$ to index $$$r$$$:
After these two operations, $$$b = [0]$$$. Therefore the minimum number of operations is $$$2$$$.
| Название |
|---|


