Cod sursa(job #2042266)

Utilizator zeboftwAlex Mocanu zeboftw Data 18 octombrie 2017 11:44:29
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

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

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

int main()
{
    int x, n, inv, y, d;

    fin >> x >> n;

    euclidE(x, n, &d, &inv, &y);

    fout << inv;

    return 0;
}