https://www.luogu.com.cn/problem/P7191
设 \(\bmod m=r\),则能得到 \(a_i=x_i\times m+r\)。
那么对于相邻的两个数 \(a_i,a_{i-1}\) 相减,就能得到 \((x_i-x_{i-1})\times m\),于是只需对所有的差求一个 \(\gcd\),便是最大的 \(m\),再分解 \(m\) 的因数即可。
# include <bits/stdc++.h>
using namespace std;
int main () {
ios :: sync_with_stdio (false);
cin .tie (0);
cout .tie (0);
int n, a, b;
cin >> n >> a >> b;
int ans = abs (a - b);
for (int i = 3; i <= n; ++ i) {
cin >> a;
ans = __gcd (ans, abs (a - b));
b = a;
}
for (int i = 2; i <= ans; ++ i) {
if (ans % i == 0) {
cout << i << ' ';
}
}
return 0;
}
标签:COCI2007,int,Luogu,P7191,abs,ans,GRANICA
From: https://www.cnblogs.com/lctj-bot/p/17064729.html