Cod sursa(job #2670032)

Utilizator TarceaIonutTarcea Tudor Ionut TarceaIonut Data 8 noiembrie 2020 18:59:12
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
#define Int long long int
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");




void invers_modular(Int a , Int b ,Int & x ,Int & y)
{
    if(b == 0)
    {
        x = 1, y = 1;
    }
    else
    {
        Int x1 , y1;
        invers_modular(b , a % b , x1 , y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}

int main()
{
    Int a , n , x , y;
    fin >> a >> n;
    invers_modular(a, n , x ,y);
    while(x < 0)
        x += n;
    fout << x;
    return 0;
}