Cod sursa(job #2973725)
| Utilizator | Data | 1 februarie 2023 19:09:20 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int a, b;
void euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1, y = 1;
}
else
{
int x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int main()
{
cin >> a >> b;
int x = 0, y;
euclid(a, b, x, y);
while (x <= 0)
x += b;
cout << x;
return 0;
}