Cod sursa(job #713784)
Utilizator | Data | 14 martie 2012 22:32:08 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<cstdio>
long long int a,n,x,y;
void gcd(long long int a,long long int b)
{
if(!b) { x=1;y=0; }
else{ gcd(b,a%b); long long int aux=x;x=y;y=aux-y*(a/b); }
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&n);
gcd(a,n);
if(x<=0) x=n+x%n;
printf("%lld",x);
return 0;
}