Cod sursa(job #2873657)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 19 martie 2022 11:16:17
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
typedef long long ll;

using namespace std;

ifstream cin("date.in");
ofstream cout("date.out");

void euclid(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return;
    }
    else
    {
        ll x1, y1;
        euclid(b, a % b, x1, y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}

int main()
{
    ll a,b,x,y;
    cin >> a>>b;
    euclid(a, b, x, y);
    if (x <= 0)
        x = b + x % b;
    cout << x;
    return 0;
}