Cod sursa(job #3165845)
| Utilizator | Data | 7 noiembrie 2023 00:19:35 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void Euclid(int a, int b, int &x, int &y)
{
if (!b) { x = 1; y = 0; }
else
{
int x0, y0;
Euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
void Rezolvare()
{
fin >> A >> N;
int x, y;
Euclid(A, N, x, y);
while (x < 0)
x += N;
fout << x << '\n';
}
int main()
{
Rezolvare();
fin.close();
fout.close();
return 0;
}
