Cod sursa(job #1606301)
| Utilizator | Data | 20 februarie 2016 09:13:57 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int a, b, d, x, y, n;
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()
{
fin >> a >> n;
d=x=y=0;
Euclid (a, n, d, x, y);
if (x<0) x+=n;
fout << x;
}
