Pagini recente » Cod sursa (job #342883) | Cod sursa (job #2369986) | Cod sursa (job #1854253) | Cod sursa (job #1804976) | Cod sursa (job #2476776)
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcdExtended(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1;
y = 0;
return;
}
gcdExtended(b, a % b, x, y);
ll aux = x;
x = y;
y = aux - (a / b) * y;
}
int main() {
ll a, n, x, y;
fin >> a >> n;
gcdExtended(a, n, x, y);
if (x < 0)
x += n;
fout << x;
return 0;
}