Cod sursa(job #1166205)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 3 aprilie 2014 12:52:55
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

typedef long long ll;

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

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

    ll x, y, A, B;

    f >> A >> B;

    modInvers( A, B, x, y );

    g << x;

    return 0;
}