#include <bits/stdc++.h>
#define lowbit(x) x&-x
using namespace std ; typedef long long LL; inline LL read(){ LL x=0; int f=1; char ch=getchar(); while(!isdigit(ch)) { if (ch=='-') f=-1; ch=getchar(); } while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return x*f; } int n; int ans; signed main() { n=read(); for(register int i=1;i<=n;i++) { int tmp=read(); if(!tmp) tmp*=-1; ans = __gcd(ans , tmp); } cout << abs(ans) << endl ; return 0; }
ax+by=c,x∈Z∗,y∈Z∗成立的充要条件是gcd(a,b)∣c。Z∗表示正整数集。html
设s=gcd(a,b),显然s∣a,而且s∣bc++
又由于x,y∈Z∗git
因此s∣ax,s∣byspa
显然要使得以前的式子成立,则必须知足c是a和b的公约数的倍数code
又由于x和y是正整数htm
因此c必然是a,b最大公约数的倍数。blog
所以,证得该定理成立get
上述裴蜀定理针对的是两个变量。那么咱们很天然的就想到这样的定理可否推广到多个变量呢?显然能够,证实方法同上。it
那这个题不就是推广后的定理的裸题吗QAQ。咱们只须要对这全部的数字求一个gcd,值得注意的是不要忘记数据中有负数,要将其变为正数再求gcd。class