Cod sursa(job #2573317)

Utilizator DobondiDavidDobondiDavid DobondiDavid Data 5 martie 2020 17:03:04
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>

using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
#define ll long long
ll inv_mod(ll a, ll b, ll &x, ll &y){
    if (b==0){
        x=1;
        y=0;
        return a;
    }
    ll val = inv_mod(b,a%b,x,y);
    ll aux=x;
    x=y;
    y=aux-y*(a/b);
}
ll a,n,x,y;
int main()
{
    fin >> a >> n;
    inv_mod(a,n,x,y);
    fout << (x+n)%n;
    return 0;
}