Cod sursa(job #2900823)
| Utilizator | Data | 12 mai 2022 11:03:32 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long a, n, x, y;
void euclid(long long a, long long b, long long &x, long long &y)
{
if (b == 0) {
x = 1;
y = 1;
}
else {
euclid(b, a%b, x, y);
long long aux = y;
y = x - (a/b) * y;
x = aux;
}
}
int main()
{
f >> a >> n;
euclid(a, n, x, y);
x = x % n;
if (x < 0)
x += n;
g << x;
f.close();
g.close();
return 0;
}
