裴蜀(贝祖)定理

简介

  1. (a_1,a_2,a_3......a_n)为n个整数,d是它们的最大公约数,那么存在整数(x_1......x_n)使得(x_1*a_1+x_2*a_2+...x_n*a_n=d)

  2. 特别来说,如果(a_1...a_n)互质(不是两两互质),那么存在整数(x_1......x_n)使得$x_1a_1+x_2a_2+...x_n*a_n=1。

  3. d其实就是最小的可以写成(x_1*a_1+x_2*a_2+...x_n*a_n)形式的正整数。

  4. 裴蜀等式有解时必然有无穷多个整数解,每组解x、y都称为裴蜀数

  5. 对任意两个整数a、b设d是它们的最大公约数。那么关于未知数x和y的线性丢番图方程(称为裴蜀等式):(ax + by = m)
    有整数解(x,y)当且仅当m是d的倍数。

记住就行了

例题

Luogu-P4549

#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#define ll long long
#define rint register int
using namespace std;
template <typename xxx>
inline void read(xxx &x) {
    x = 0;
    int f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c <= '9' && c >= '0') {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename xxx>
inline void print(xxx x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}
const int N = 300100;
const int mod = 100003;
const int maxn = 200100;
const int inf = 0x7fffffff;
const int key = 131;
const double eps = 1e-9;
int n,m;
int c[maxn];
inline int gcd(int a,int b) {
	while(b ^= a ^= b ^= a %= b);
	return a;
}
int main() {
	read(n);
	for(rint i = 1;i <= n; ++i) {
		read(c[i]);
		if(c[i] == 0) continue;
		if(i > 1) m = gcd(m,c[i]);
		else m = c[i];
	}
	if(m < 0) m = -m;
	print(m);
	return 0; 
}
/*
*/
原文地址:https://www.cnblogs.com/Thomastine/p/11857952.html