Cod sursa(job #577909)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 10 aprilie 2011 19:15:42
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>

using namespace std;

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

int main()
{
    ifstream in ("inversmodular.in");
    int A, N, X, Y;
    in >> A >> N;
    euclid(A, N, X, Y);
    while( X < 0 )
        X += N;

    ofstream out("inversmodular.out");
    out<< X << '\n';
    return 0;
}