Cod sursa(job #448910)
| Utilizator | Data | 4 mai 2010 22:54:58 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
int c,d,n,e;
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0) {
d = a;
x = 1;
y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int i;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
int a, b, c, d, x, y;
scanf("%d %d", a, b);
c = 1;
euclid(a,b,d,x,y);
while ( x < 0) x = x + a;
printf("%d ", x);
return 0;
}
