Cod sursa(job #3183267)

Utilizator Samoila_AlexandruSamoilaAlexandru Samoila_Alexandru Data 11 decembrie 2023 13:35:00
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>

using namespace std;

ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

void gcd(long long a, long long b, long long& x, long long& y)
{
    if(!b)
    {
        x=1, y=0;
        return;
    }
    else {
        long long xx, yy;
        gcd(b, a%b, xx, yy);
        x=yy;
        y=xx-(a/b)*yy;
    }
}

long long a, n, rez, y;

int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);

    fin>>a>>n;
    fin.close();

    gcd(a, n, rez, y);

    fout<<rez;

    fout.close();
    return 0;
}