Cod sursa(job #2931249)

Utilizator epicrobloxgamerTiberiu Tiron epicrobloxgamer Data 30 octombrie 2022 18:38:36
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define Vl vector<ll>
#define Vb vector<bool>
#define nl '\n'
#define pf push_front
#define VPl vector < pair < ll, ll > >
#define Graph set<ll>
#define forn(i, a, b) for(ll i = a; i <= b; i++)
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid(ll a, ll b, ll & d, ll & x, ll & y)
{
    if (b == 0)
    {
        d = a;
        x = 1, y = 1;
    }
    else
    {
        ll x1, y1;
        euclid(b, a % b, d, x1, y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}

void solve()
{
    ll a, b;
    in >> a >> b;
    ll d, x, y;
    euclid(a, b, d, x, y);
    if (d != 1)
        out << 0;
    else {
        while (x < 0)
            x = (x % b) + b;
        out << x;
    }
    
}

int main()
{
    IO;
    ll t;
        solve();
        return 0;
}