Cod sursa(job #2376889)

Utilizator edynator34Nechitoaia George-Edward edynator34 Data 8 martie 2019 18:26:26
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
typedef long long ull;
ull mod,a,x,y,d;

int euclid_e(ull a, ull b, ull &x, ull &y, ull &d){
    if(b==0){
        x=1;
        d=a;
        y=0;
    }
    else{
        ull x0, y0;
        euclid_e(b,a%b,x0,y0,d);
        x=y0;
        y=x0-a/b*y0;
    }
}

int main()
{
    in>>a>>mod;
    euclid_e(mod,a,x,y,d);
    while(y<1) y+=mod;
    out<<y<<'\n';
    return 0;
}