Files
python/TangDou/LuoGuBook/P4549.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

20 lines
476 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}