Cod sursa(job #1686135)

Utilizator ArambasaVlad Arambasa Arambasa Data 12 aprilie 2016 08:43:11
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int x0, y0, x, y, A, N;
void euclid(int a, int b)
{
    if(b)
    {
        euclid(b, a % b);
        x0 = x;
        y0 = y;
        x = y0;
        y = x0 - (a / b) * y0;
    }
    else
    {
        x = 1;
        y = 0;
    }
}
int main()
{
    fin>>A>>N;
    euclid(A, N);
    while(x < 0)
    {
        x += N;
    }
    fout<<x;
    return 0;
}