Cod sursa(job #420906)
Utilizator | Data | 20 martie 2010 18:54:41 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <cstdio>
#define ll long long
int a, n;
void cmmdc(int a, int n, ll &x, ll &y)
{
if (!n)
{
x=1;
y=0;
} else
{
cmmdc(n, a%n, x, y);
ll aux=x;
x=y;
y=aux-y*(a/n);
}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&n);
ll x, y;
cmmdc(a,n,x,y);
printf("%d",(n+x%n)%n);
}