Cod sursa(job #2520506)

Utilizator ioanavasi16Vasile Ioana ioanavasi16 Data 9 ianuarie 2020 15:03:10
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>
#define LL long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int T,x,y,A,N;
LL a,b,L,inv,p;
void cmmdc(int a,int b,LL &x,LL &y)
{
    if(!b)
    {
        x=1;
        y=0;
    }
    else
    {
        cmmdc(b,a%b,x,y);
        LL aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}

int main()
{
    fin>>A>>N;
    cmmdc(A,N,inv,p);
    if(inv<=0)
        inv=N+inv%N;
    fout<<inv;
    return 0;
}