Cod sursa(job #1784745)
| Utilizator | Data | 20 octombrie 2016 14:24:18 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid_ext(int a, int b, int &x, int &y)
{
if (b != 0)
{
int x0, y0;
euclid_ext(b, a%b, x0, y0);
x = y0;
y = x0 - y0*(a / b);
}
else
{
x = 1, y = 0;
}
}
int main()
{
int a, N;
in >> a >> N;
int x, y;
euclid_ext(a, N, x, y);
while (x < 0)
x += N;
out << x;
return 0;
}