Cod sursa(job #865475)

Utilizator ericptsStavarache Petru Eric ericpts Data 26 ianuarie 2013 15:50:36
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euc(int a,int b,int &x,int &y)
{
    if(!b)
    {
        x = 1;
        y = 0;
    }
    else
    {
        int x0,y0;
        euc(b,a%b,x0,y0);
        x = y0;
        y = x0 - (a/b)* y0;
    }
}

int main()
{
    int A,N;
    int x,y;
    in >> A >> N;
    euc(A,N,x,y);
    while(x<0)
        x+=N;
    out << x;
    return 0;
}