Cod sursa(job #2702599)
| Utilizator | Data | 4 februarie 2021 21:42:30 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
int a, n;
void euclid(int a, int b, int &x, int &y) {
if (b == 0)
x = 1, y = 0;
else {
int x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int main() {
int x, y;
ifstream f("inversmodular.in");
f >> a >> n;
f.close();
euclid(a, n, x, y);
while (x < 0)
x += n;
ofstream g("inversmodular.out");
g << x;
g.close();
return 0;
}