题解,看完你对最大公约数,求余一定有更深的认识
事实1.当序列中有奇数又有偶数时,2就是那个k
事实2.当 \(a[i] \ mod \ b = c,\forall i\in[1,n]\)时
-
$ a[i] \ mod \ 2b = c \ ,if(a[i]//b)==$偶数
-
$ a[i] \ mod \ 2b = c+b \ ,if(a[i]//b)==$奇数
事实3.如上,对非有序的序列一样成立
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[105]={0};
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)cin>>a[i];
ll x=abs(a[2]-a[1]);
for(int i=3;i<=n;i++)x=__gcd(x,abs(a[i]-a[1]));
cout<<2*x<<endl;
}
return 0;
}
标签:Almost,Make,Equal,long,int,Mod,ll,mod
From: https://www.cnblogs.com/pure4knowledge/p/17930977.html