Cod sursa(job #2476788)

Utilizator Mirela_MagdalenaCatrina Mirela Mirela_Magdalena Data 19 octombrie 2019 11:29:29
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>

using namespace std;

ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

int a, n;


pair<long long, long long> euclid_ext(int x, int y)
{
    if(y == 0)
    {
        return {1, 0};
    }
    pair<long long, long long> p = euclid_ext(y, x%y);
    return {p.second, p.first-(x/y)*p.second};
}


int main()
{
    f>>a>>n;
    pair<long long, long long> rez = euclid_ext(a, n);
    while(rez.first < 0)
        rez.first += n;
    g<<rez.first;


    return 0;
}