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