Cod sursa(job #2446105)

Utilizator ArkhamKnightyMarco Vraja ArkhamKnighty Data 7 august 2019 10:05:18
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>

using namespace std;

ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");

int a, n;

void citire()
{
    cin >> a >> n;
}

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

void print(long long x)
{
    if (x <= 0)
       x = n + x % n;
    cout << x;
}

int main()
{
    long long x = 0, y;
    citire();
    invers(x,y,a,n);
    print(x);
    return 0;
}