Cod sursa(job #2379072)
Utilizator | Data | 12 martie 2019 21:02:22 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
int invers_modular(int a, int m)
{
int y, y0 = 0, y1 = 1;
int aux = m, r, c;
while(a!=0)
{
r = m%a;
c = m/a;
m = a;
a = r;
y = y0 - c*y1;
y0 = y1;
y1 = y;
}
if(y0<0) y0 = aux + y0%aux;
return y0;
}
int main()
{
int a, b;
cin>>a>>b;
cout<<invers_modular(a, b);
return 0;
}