Cod sursa(job #2084019)

Utilizator topala.andreiTopala Andrei topala.andrei Data 8 decembrie 2017 15:28:14
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

void Invers_Modular_Euclid(int A,int N,int &x,int &y)
{
    int x0,y0;
    if (N == 0)
    {
        x=1;
        y=0;
        return;
    }
    Invers_Modular_Euclid(N, A%N, x0, y0);
    x = y0;
    y = x0 - (A/N) * y0;
}
int main()
{
    int N,A,x,y;
    f>>A>>N;

    Invers_Modular_Euclid(A,N,x,y);

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

    g<<x;
}