Cod sursa(job #2070405)

Utilizator amaliarebAmalia Rebegea amaliareb Data 19 noiembrie 2017 15:27:07
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>
#include <iostream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n, a, x, y;

void euclid(int a, int b)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        int x0, y0;
        euclid(b, a % b);
        x0 = x;
        y0 = y;
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    f >> a >> n;
    euclid(a, n);
    g << x << '\n';
    return 0;
}