1. 程式人生 > 實用技巧 >擴充套件歐幾里德

擴充套件歐幾里德

#include <bits/stdc++.h>

#define Enter puts("")
#define Space putchar(' ')

using namespace std;

typedef long long ll;
typedef unsigned long long Ull;
typedef double Db;

inline ll Read()
{
    ll Ans = 0;
    char Ch = getchar() , Las = ' ';
    while(!isdigit(Ch))
    {
        Las = Ch;
        Ch 
= getchar(); } while(isdigit(Ch)) { Ans = (Ans << 3) + (Ans << 1) + Ch - '0'; Ch = getchar(); } if(Las == '-') Ans = -Ans; return Ans; } inline void Write(ll x) { if(x < 0) { x = -x; putchar('-'); } if(x >= 10
) Write(x / 10); putchar(x % 10 + '0'); } inline int Gcd(int a , int b) { return b ? Gcd(b , a % b) : a; } inline int Extra_Gcd(int a , int b , int &x , int &y) { if(!b) { x = 1; y = 0; return a; } int r = Extra_Gcd(b , a % b , x , y);
int t = x; x = y; y = t - a / b * y; return r; } int main() { int a , b; int x , y; a = Read(); b = Read(); Extra_Gcd(a , b , x , y); Write(x) , Space , Write(y); return 0; }