Cod sursa(job #2848191)

Utilizator MateiStoianStoian Matei Octavian MateiStoian Data 12 februarie 2022 10:57:57
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void euclid(ll a,ll b,ll &x,ll &y){
    if(b == 0){
        x = 1;
        y = 0;
    }
    else{
        ll x0,y0;
        euclid(b,a%b,x0,y0);
        x = y0;
        y = x0 - y0*(a/b);
    }
}
int main(){
    freopen("inversmodular.in","r",stdin);
    freopen("inversmodular.out","w",stdout);
    ll a,n;
    ll x,y;
    cin>>a>>n;
    euclid(a,n,x,y);
    while (x<0)
    {
        x+=n;
    }
    
    cout<<x;
    return 0;
}