Cod sursa(job #2758865)

Utilizator rusenmihai101@gmail.comMihai Rusen [email protected] Data 13 iunie 2021 19:18:05
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
using namespace std;
using ll = long long;

const string name("inversmodular");
ifstream fin(name + ".in");
ofstream fout(name + ".out");


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

int main(){

    ll a, n;
    fin >> a >> n;
    ll x, y;
    Euclid(a, n, x , y);
    while(x < 0)
        x += n;
    fout << x;

    return 0;
}