Cod sursa(job #2070407)

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

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

void euclid(long long a, long long b)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        long long 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);
    while(x < 0) x += n;
    g << x << '\n';
    return 0;
}