Cod sursa(job #284810)
| Utilizator | Data | 21 martie 2009 23:17:08 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <stdio.h>
#define ll long long
void ee(ll a,ll b,ll &x,ll &y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
ll x0,y0;
ee(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
ll a,n,sol,x;
scanf("%d%d", &a,&n);
ee(a,n,sol,x);
while (sol < 0)
sol += n;
printf("%lld\n", sol);
return 0;
}
