Pagini recente » Cod sursa (job #3335211) | Cod sursa (job #3316093) | Borderou de evaluare (job #1180589) | Cod sursa (job #158201) | Cod sursa (job #3350671)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(v) begin(v), end(v)
#define al(v, l, r) begin(v) + l, begin(v) + r + 1
#define sz(v) (int)v.size()
#define pb push_back
#define pob pop_back
#define fs first
#define sd second
constexpr int inf = 2e9;
constexpr ll infll = 4e18;
ll gcde(ll a, ll b, ll& x, ll& y) {
if (!b) {
x = 1;
y = 0;
return a;
}
ll x0, y0, g = gcde(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return g;
}
int a, n;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
cin >> a >> n;
ll ans, _;
gcde(a, n, ans, _);
cout << ((ans % n) + n) % n << "\n";
}