Pagini recente » Cod sursa (job #2916644) | Cod sursa (job #187177) | Borderou de evaluare (job #218221) | Cod sursa (job #2550142) | Cod sursa (job #3237855)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ifstream fin( "inversmodular.in" );
ofstream fout( "inversmodular.out" );
void euclid_ext( int a, int b, int &x, int &y ) {
if ( b == 0 ) {
x = 1, y = 0;
return;
}
int px, py;
euclid_ext(b, a % b, px, py);
x = py;
y = px - (a / b) * py;
}
int main() {
ios_base::sync_with_stdio(0);
fin.tie(0);
int a, n, x, y;
fin >> a >> n;
euclid_ext(a, n, x, y);
fout << ((ll)x % n + n) % n;
fin.close();
fout.close();
return 0;
}