Cod sursa(job #234181)
| Utilizator | Data | 20 decembrie 2008 10:59:25 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <cstdio>
using namespace std;
int a,n,x, y;
void euclid( int a, int b, int &x, int &y ) {
if ( b==0 ) {
x = 1, y = 0;
return ;
}
int x0, y0, c = a/b;
euclid( b, a%b, x0, y0 );
x = y0;
y = x0 - c * y0;
}
int main() {
freopen( "inversmodular.in", "r", stdin );
freopen( "inversmodular.out", "w", stdout );
scanf( "%d %d", &a, &n );
euclid( n, a, x, y );
while ( y < 0 ) y += n;
printf("%d\n", y);
return 0;
}
