Cod sursa(job #2257945)

Utilizator ciocirlanrCiocirlan Robert ciocirlanr Data 10 octombrie 2018 17:46:51
Problema Invers modular Scor 0
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,x1,y1;

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,x1,y1);

    if(x1 <= 0){
        x1 = b + x1%b;
    }

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

    return 0;
}