Cod sursa(job #1733980)

Utilizator liviu23Liviu Andrei liviu23 Data 26 iulie 2016 11:41:23
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>
#define ll long long
using namespace std;

void euclid(ll a,ll n,ll &x,ll &y) {
    if(!n) {
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    euclid(n,a%n,x1,y1);
    x=y1;
    y=x1-(a/n)*y1;
}

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