P4549 裴蜀定理
题面:https://www.luogu.org/problemnew/show/P4549
裴蜀定理:ax+by=c,x∈Z∗,y∈Z∗成立的充要条件是gcd(a,b)∣c。Z∗表示正整数集。
Code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
inline int gcd(int x, int y) {
return y ? gcd(y, x%y) : x;
}
int n;
int main() {
scanf("%d", &n);
int ans = 0, tmp;
for(int i=1; i<=n; i++) {
scanf("%d", &tmp);
if(tmp < 0) tmp = -tmp;
ans = gcd(ans, tmp);
}
printf("%d", ans);
}