Cod sursa(job #2669575)
| Utilizator | Data | 7 noiembrie 2020 11:44:01 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0;
int rez = euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
return rez;
}
int main()
{
int a, n;
int x, y;
f >> a >> n;
euclid(a, n, x, y);
while (x < 0)
x += n;
g << x;
return 0;
}
