Cod sursa(job #447874)
| Utilizator | Data | 1 mai 2010 17:54:34 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <cstdio>
void euclid(long long a, long long b, long long &x, long long &y){
if(!b)
x = 1, y = 0;
else {
euclid(b, a%b, x, y);
long long aux = x;
x = y;
y = aux - y*(a/b);
}
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
long long A, N, x, y;
scanf("%lld %lld", &A, &N);
euclid(A, N, x, y);
if(x <= 0)
x = N+x%N;
printf("%lld\n", x);
return 0;
}
