#PU1471. USACO 2025 January Contest, Silver — Problem 2. Farmer John's Favorite Operation
USACO 2025 January Contest, Silver — Problem 2. Farmer John's Favorite Operation
USACO 2025 January Contest, Silver — Problem 2. Farmer John's Favorite Operation
题目描述
It is another cold and boring day on Farmer John's farm. To pass the time, Farmer John has invented a fun leisure activity involving performing operations on an integer array. Farmer John has an array of () non-negative integers and an integer (). Then, FJ will ask Bessie for an integer . In one operation, FJ can pick an index and subtract or add to . FJ's boredom value is the minimum number of operations he must perform so that is divisible by for all . Among all possible , output FJ's minimum possible boredom value.
输入格式
The first line contains (), the number of independent test cases to solve. The first line of each test case contains and . The second line of each test case contains (). It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output an integer on a new line containing FJ's minimum possible boredom value among all possible values of .
数据范围
(见题面原文)
样例
样例 1
2
5 9
15 12 18 3 8
3 69
1 988244353 998244853
10
21
In the first test case, one optimal choice of $x$ is $3$. FJ can perform $10$
operations to make
$a = [12, 12, 21, 3, 12]$.