Cod sursa(job #2062331)
Utilizator | Data | 10 noiembrie 2017 11:23:04 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <cstdio>
using namespace std;
int n,a,aux,xo,xi,x,r,c;
int main()
{
freopen ("inversmodular.in", "r", stdin);
freopen ("inversmodular.out", "w", stdout);
scanf ( "%d%d", &a, &n );
xo=1; xi=0;
aux=n;
while (aux!=0)
{
r=a%aux;
c=a/aux;
a=aux; aux=r;
x=xo-c*xi;
xo=xi;
xi=x;
}
if(xo<0) xo+=n;
printf("%d\n", xo);
return 0;
}