Pagini recente » Cod sursa (job #1806864) | Cod sursa (job #2186448) | Cod sursa (job #2765241) | Cod sursa (job #2290946) | Cod sursa (job #2476773)
#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);
fout << x;
return 0;
}