Cod sursa(job #1174808)
| Utilizator | Data | 23 aprilie 2014 22:36:33 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include<fstream>
#include<iostream>
using namespace std;
void euclid_ext (int a, int b, int& d, int& x, int& y)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid_ext(b, a%b, d, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
}
}
int main()
{
int a, n;
ifstream fin("inversmodular.in");
fin>>a>>n;
int d, x, y;
euclid_ext(a, n, d, x, y);
while (d<0)
x += n;
ofstream fout("inversmodular.out");
fout<<x<<'\n';
return 0;
}
