裴蜀定理内容:\(ax+by=c\), \(x \in Z^∗\), \(y \in Z^∗\) 成立的充要条件是 \(gcd⁡(a, b) ∣ c\)\(Z^*\) 表示正整数集。

luogu:https://www.luogu.com.cn/problem/P4549

给定一个序列 \(a\),找到一个序列 \(x\),使得 \(\sum_{i = 1}^n a_ix_i\) 最小。

#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL n, a, ans;
LL gcd(LL a, LL b){
	return b ? gcd(b, a % b) : a;
}
int main(){
	cin >> n;
	for (int i = 0; i < n; i ++ ){
		cin >> a;
		if (a < 0) a = -a;
		ans = gcd(ans, a);
	}
	cout << ans << "\n";
	return 0;
}
posted on 2022-04-27 10:59  Hamine  阅读(119)  评论(0编辑  收藏  举报