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