Cod sursa(job #1152096)
| Utilizator | Data | 24 martie 2014 15:45:01 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <cstdio>
using namespace std;
int a,n;
void cmmdc(int a,int b,int &x,int &y) {
int x0,y0;
if (b == 0) {
x = 1,y = 0;
} else {
cmmdc(b,a%b,x0,y0);
x = y0;
y = x0-(a/b)*y0;
}
}
int main() {
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&n);
int x,y;
cmmdc(a,n,x,y);
if (x < 0) x = n + x%n;
printf("%d\n",x);
return 0;
}
