Cod sursa(job #2313621)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 7 ianuarie 2019 11:17:59
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>

using namespace std;

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

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

int main()
{
    int a, n;
    fin >> a >> n;
    int rasp = 0, idk = 342;
    chestie(rasp, idk, a, n);
    if (rasp <= 0)
        rasp = n + rasp % n;
    fout << rasp << '\n';
    return 0;
}