Cod sursa(job #2050422)

Utilizator KemyKoTeo Virghi KemyKo Data 28 octombrie 2017 09:51:12
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <iostream>
#include <fstream>
#define ll long long

using namespace std;

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

ll A, MOD, x, y;

void gcd(ll &x, ll &y, ll a, ll b)
{
    if (b==0){
        x=1;y=1;
    }else {
        gcd(x, y, b, a%b);
        ll aux = x;
        x = y;
        y = aux-y*(a/b);
    }
}

int main()
{
    f>>A>>MOD;
    gcd(x, y, A, MOD);
    if (x<0) x=MOD+x%MOD;
    g<<x;
    return 0;
}