欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

扩展欧几里得

程序员文章站 2024-02-11 16:45:16
...

扩展欧几里得

#include <iostream>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cstdio>
#include <vector>
#include <queue>
#include <limits>
using namespace std;

typedef long long ll;
const int MAXN = 100005;

int extgcd(int a, int b, int &x, int &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    int xx, yy;
    int ret = extgcd(b, a % b, xx, yy);
    x = yy;
    y = xx - (a / b) * yy;
    return ret;
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    extgcd(4, 11, x, y);
    cout << x << " " << y;

    return 0;
}


相关标签: 扩展欧几里得