Cod sursa(job #3187072)

Utilizator stefanvilcescuStefan Vilcescu stefanvilcescu Data 27 decembrie 2023 12:15:39
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>

using namespace std;
using ll=long long;

void invMod(int a, int b, ll &x, ll &y){
    ll aux;
    if(!b){
        x=1;
        y=0;
    }else{
        invMod(b, a%b, x, y);
        aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}

int main()
{
    ifstream fin("inversmodular.in");
    ofstream fout("inversmodular.out");
    int n, a;
    ll x, y;
    fin>>a>>n;
    x=y=0;
    invMod(a, n, x, y);
    fout<<x;
    return 0;
}