Cod sursa(job #3357404)

Utilizator malita.dragosMalita Dragos-Ionut malita.dragos Data 9 iunie 2026 12:48:54
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>

using namespace std;

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

void euclid(int a, int b, long long &d, long long &x, long long &y)
{
    if (b == 0) {
        d = a;
        x = 1;
        y = 0;
    } else {
        long long x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    int a,n;
    fin>>a>>n;
    long long x,y,d;
    euclid(a,n,d,x,y);

    fout<<x;

    return 0;
}