根据 $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\n",abs(ans)); return 0; }
2024-03-23 19:20:58
根据 $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\n",abs(ans)); return 0; }