裴蜀定理的基本内容是】
若a,b是整数,且gcd(a,b)=d,那么对于任意的整数x,y,ax+by都一定是d的倍数,特别地,一定存在整数x,y,使ax+by=d成立。
如何证明这个定理呢?
- 假设c是ax+by的最小正整数解,也即是ax+by=c,d=(a,b)
- 根据最大公约数的性质及同余方程的性质,可以知道:d|a,d|b,d|(ax+by)
- 假设r是a%c的余数,t是a/c的整除商,那么就有r=a-t*c=a-t*(ax+by)(因为c是ax+by的最小正整数解)
- 整理可得r=a(1-tx)+bty,将1-tx与ty看作一个整体,就可以得出r也是a与b的线性组合,那么同样可以表示为ax+by的形式
- 因为c已经是ax+by的最小正值,所以r只能为0
- 因此a%c=0,即c|a,c|b,可推出c|d,因为c是最小正整数解,所以c=d
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <queue>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#pragma GCC optimize(2)
#pragma warning(disable:4996)
#define lldin(a) scanf("%lld", &a)
#define println(a) printf("%lld\n", a)
#define print(a) printf("%lld ", a)
#define reset(a, b) memset(a, b, sizeof(a))
#define debug std::cout<<"procedures above are available"<<"\n";
#define BigInteger __int128
const int INF = 2e9 + 2;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1e9 + 7;
//template<typename T>
//inline BigInteger nextBigInteger()
//{
// BigInteger tmp = 0, si = 1;char c; c = getchar();
// while (!isdigit(c))
//{if (c == '-')si = -1;c = getchar();}
// while (isdigit(c))
// {tmp = tmp * 10 + c - '0';c = getchar();}
// return si * tmp;
//}
//std::ostream& operator<<(std::ostream& os, __int128 T)
//{
// if (T<0) os<<"-";if (T>=10 ) os<<T/10;if (T<=-10) os<<(-(T/10));
// return os<<( (int) (T%10) >0 ? (int) (T%10) : -(int) (T%10) ) ;
//}
//void output(BigInteger x)
//{
// if (x < 0)
// {x = -x;putchar('-');}
// if (x > 9) output(x / 10);
// putchar(x % 10 + '0');
// }
/**The doorway has been blocked,whether to knock it out or find another way is a vital choice**/
/**Last Remote**/
ll gcd(ll a, ll b)
{
return b == 0 ? a : gcd(b, a%b);
}
int DETERMINATION()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
ll n;
std::cin >> n;
ll k;
std::cin >> k;
ll ans = k;
for (int i = 1; i <= n - 1; i++)
{
ll tmp;
std::cin >> tmp;
tmp = abs(tmp);
ans = gcd(tmp, ans);
}
std::cout << ans << "\n";
return 0;
}