根据 $exgcd$ 的定理,这种方程的最小解就是 $gcd$.
Code:
#include <cstdio> #include <algorithm> using namespace std; int main() { int n,i,a,ans; scanf("%d%d",&n,&ans); for(i=2;i<=n;++i) scanf("%d",&a),ans=__gcd(a,ans); printf("%d ",abs(ans)); return 0; }
根据 $exgcd$ 的定理,这种方程的最小解就是 $gcd$.
Code:
#include <cstdio> #include <algorithm> using namespace std; int main() { int n,i,a,ans; scanf("%d%d",&n,&ans); for(i=2;i<=n;++i) scanf("%d",&a),ans=__gcd(a,ans); printf("%d ",abs(ans)); return 0; }