Cod sursa(job #2257930)

Utilizator ciocirlanrCiocirlan Robert ciocirlanr Data 10 octombrie 2018 17:28:50
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
using namespace std;
#define ll long long
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");

ll a,b,x,y;

void Euclid_Extins(ll a , ll b , ll &x , ll &y){

     if(!b) x = 1, y = 0;
        else {
            Euclid_Extins(b,a%b,x,y);
            ll aux = x;
            x = y;
            y = aux - y * (a/b);

        }
 }


int main(){

    in >> a >> b;
    Euclid_Extins(a,b,x,y);

    out << x;

    if(x < 0)
        x = b + x%b;

    in.close();
    out.close();

    return 0;
}