Cod sursa(job #1046825)
| Utilizator | Data | 3 decembrie 2013 16:47:05 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <cstdio>
int A, N, x, y;
void cmmdc(int a, int b, int &x, int &y)
{
int x1, y1;
if (b)
{
cmmdc(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return;
}
x = 1;
y = 0;
}
void Citire()
{
scanf("%d %d", &A, &N);
}
void Rezolvare()
{
cmmdc(A, N, x, y);
if (x < 0)
x += N;
printf("%d", x);
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
Citire();
Rezolvare();
return 0;
}
