Cod sursa(job #2301485)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 13 decembrie 2018 00:25:00
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>

using namespace std;

ifstream fin  ("inversmodular.in");
ofstream fout ("inversmodular.out");

long long a, n, x, y;

inline void euclidpp (long long a, long long b, long long &x, long long &y){
    long long xa, ya, d;
    if (b == 0){
        y = 0, x = 1;
    }
    else{
        euclidpp (b, a%b, xa, ya), x = ya, y = xa - (a/b)*ya;
    }
}

int main(){
    fin >> a >> n;
    euclidpp (n, a, x, y);
    while (y < 0){
        y += n;
    }
    fout << y;
    return 0;
}