Cod sursa(job #2594037)
Utilizator | Data | 5 aprilie 2020 12:10:24 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include<iostream>
#define LL long long
using namespace std;
int a,n;
void euclid_extins(LL &x,LL &y,int a,int b)
{
if(!b)
x = 1,y = 0;
else
{
euclid_extins( x, y, b, a%b);
LL aux = x;
x = y;
y = aux - y *(a / b);
}
}
int main()
{
LL inv = 0,ins;
cin>>a>>n;
euclid_extins(inv,ins,a,n);
if(inv <= 0)
inv = n +inv % n;
cout<<inv;
return 0;
}