Cod sursa(job #2930964)

Utilizator TheAndreiEnache Andrei Alexandru TheAndrei Data 29 octombrie 2022 21:50:47
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;

#define ll long long

ll int A, N;

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

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

int main()
{
    ll inv = 0, ins;

    fin>>A>>N;
    gcd(inv, ins, A, N);

    if (inv <= 0)
       inv = N + inv % N;

    fout<<inv;
    return 0;
}