Cod sursa(job #2555386)

Utilizator bem.andreiIceman bem.andrei Data 23 februarie 2020 22:47:49
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream r("inversmodular.in");
ofstream w("inversmodular.out");
int A, N;
void Euclid(long long cx, long long cy, int a, int b)
{
    if (b==0)
    {
        cx=1;
        cy=0;
    }
    else
    {
        Euclid(cx, cy, b, a%b);
        long long aux=cx;
        cx=cy;
        cy=aux-cy*(a/b);
    }
}
int main()
{
    long long inv=0, ins;
    r>>A>>N;
    Euclid(inv, ins, A, N);
    if (inv <= 0)
    {
        inv=N+inv%N;
    }
    w<<inv;
    return 0;
}