Cod sursa(job #1496977)
| Utilizator | Data | 5 octombrie 2015 21:37:25 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <cstdio>
using namespace std;
void euclid(int a, int b, long long& x, long long& y){
if(not b){
x = 1;
y = 0;
return;
}
euclid(b,a%b,x,y);
long long aux = x;
x = y;
y = aux - (a/b)*y;
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int n,a;
scanf("%d %d", &a, &n);
long long x, y;
euclid(n,a,x,y);
if(x < 0)
x = n + x % n;
printf("%d\n", x);
return 0;
}
