就是每两项相减,肯定能被模数整除。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; const int Maxn=;
int f[Maxn],n,Ans;
int Gcd(int a,int b) {if (b==) return a; return Gcd(b,a%b);}
inline int Abs(int x) {return x>?x:-x;}
int main()
{
while (true)
{
n=;
scanf("%d",&f[++n]);
if (f[n]==) break;
while (f[n]!=) scanf("%d",&f[++n]);
n--;
for (int i=;i<n;i++)
f[i]=f[i]-f[i+];
Ans=f[];
for (int i=;i<n;i++)
Ans=Gcd(f[i]==?Ans:f[i],Ans);
printf("%d\n",Abs(Ans));
}
return ;
}
C++