斐蜀定理

Published on7/29/2025
Created on 10/26/2021

裴蜀(péi shǔ)Bézout /beɪzu/ 又称贝祖定理 内容:

a,bZ, x,yZ, ax+by=gcd(a,b)\forall a,b\in\mathbb{Z}, \ \exists x,y\in\mathbb{Z}, \ ax+by=\gcd(a,b)

更一般地说:

The integers of the form ax+byax+by are exactly the multiples of gcd(a,b)\gcd(a,b).

如果 ax+by=max+by=m 有解,那么 mm 一定是 gcd(a,b)\gcd(a,b) 的若干倍。 这可用于判断这种类型的方程(丢番图方程)是否有解。

若关于整数 $x$ 和 $y$ 的方程 $ax+by=1$ 有解,即这里 $m=1$ ,$1$ 是$\gcd(a,b)$ 的倍数,那么显然有 $\gcd(a,b)=1$ 。即 $a$ 和 $b$ 互质。
不定方程 ax+by=m 有整数解    gcd(a,b)m\text{不定方程}\ ax+by=m\ \text{有整数解} \iff \gcd(a,b)\mid m

又有:关于整数 xxyy 的二元函数 f(x,y)=ax+byf(x,y)=ax+by 的最小正整数取值是 gcd(a,b)\gcd(a,b),即:

a,bZ,min{max+by=mN,x,yZ}=gcd(a,b)\forall a,b\in\mathbb{Z}, \min\{m \mid ax+by=m\in\mathbb{N}^*, x,y\in\mathbb{Z} \}=\gcd(a,b)

推广到 nn 元函数:关于整数 xi (i[1,n])x_i\ (i\in[1,n])nn 元函数 f(x1,x2,,xn)=i=1naixif(x_1,x_2,\dots,x_n)=\sum^n_{i=1}a_ix_i 的最小正整数取值是 gcd(a1,a2,,an)\gcd(a_1,a_2,\dots,a_n)

证明

[[裴蜀定理的证明]]

链接

相关题目

P4549 【模板】裴蜀定理 - 洛谷 求出序列 AA 中所有元素的最大公约数(正值)即为答案 参考代码:

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
//---//
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

typedef unsigned int u;
typedef long long ll;
typedef unsigned long long llu;

#define rep(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, b, a) for (ll i = b; i >= a; i--)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
  ll n, g, k;
  scanf("%lld%lld", &n, &g);
  while (n--) {
    scanf("%lld", &k);
    g = gcd(k, g);
  }
  printf("%lld", abs(g));
}

//https://www.luogu.com.cn/record/60899570

证明

[[裴蜀定理]] 参考:Bézout’s identity - Wikipedia 给定任意非零整数 aabb ,令:

S={ax+byax+by>0,x,yZ}S=\{ax+by\mid ax+by>0,x,y\in\mathbb{Z}\}

xx±1\pm1 ,且 yy00 时,ax+by=±aax+by=\pm a,必有一值属于 SS ,令 d=as+bt=Smind=as+bt=S_{\min},我们要证明 d=gcd(a,b)d=\gcd(a,b) ,即是要证明:

{dadbc 满足 cacb, cd\begin{cases} d\mid a\\ d\mid b\\ \forall c\ \text{满足}\ c|a\wedge c|b,\ c\geq d \end{cases}

aadd 实施带余除法,表示为:

a=qd+r(q,rZ, 0r<d)a=qd+r\quad(q,r\in\mathbb{Z},\ 0\leq r<d)

我们要证明 r=0r=0 ,尝试表示一下 rr

r=aqd=aq(as+bt)=aaqs+bqt=a(1qs)+bqt\begin{aligned} r&=a-qd\\ &=a-q(as+bt)\\ &=a-aqs+bqt\\ &=a(1-qs)+bqt \end{aligned}

可以看到,rr 也被表示为了 ax+byax+by 的形式,根据 rr 原本的定义,我们可以知道:

rS{0}r\in S\cup\{0\}

根据定义,d=Smind=S_{\min} ,但 0r<d0\leq r<d ,故 rr 不能属于 SS ,否则就与 dd 是最小值矛盾了,因此,我们只能断定 r=0r=0,也就是 dad\mid a 。 我们能用同样的方法证明 dbd\mid b 。 要证明最后一个子命题,我们令 a=cua=cub=cvb=cv ,这就有:

d=as+bt=cus+cvt=c(us+vt)\begin{aligned} d&=as+bt\\ &=cus+cvt\\ &=c(us+vt) \end{aligned}

这就意味着:dcd\mid c,因此 cdc\geq d。 综上,Smin=d=gcd(a,b)S_{\min}=d=\gcd(a,b)。 这样,函数 ax+byax+by 的所有取值均为 as+btas+bt 加减几个 aabb 所得到的。 因为 dad\mid adbd\mid b ,无论如何,结果总会是 d=gcd(a,b)d=\gcd(a,b) 的整数倍,所以 ax+by=max+by=m 有整数解当且仅当 gcd(a,b)m\gcd(a,b)\mid m