Cod sursa(job #2481341)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 26 octombrie 2019 19:24:46
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");

long long n;

void euclid (int a, int b, long long &x, long long &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        long long x1, y1;
        euclid(b, a%b, x1, y1);
        x = y1;
        y = x1 + y1 * (a/b);
        x = (x+n)%n;
        y = (y+n)%n;
    }
}

int main()
{
    //     a*x = 1 (mod n)
    // <=> x = 1/a (mod n)
    int a;
    fin >> a >> n;
    long long r, g;
    euclid(a, n, r, g);
    fout << r;
    return 0;
}