Files
python/TangDou/LuoGuBook/P4549.cpp

20 lines
476 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
//最大公约数,辗转相除法
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
scanf("%d", &n);
int d = 0, a;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
d = gcd(d, abs(a)); //负数没法求最大公约数,这里认为系数都是正数,让变量x,y吃进去这个负号
}
printf("%d", d);
return 0;
}