Pagini recente » Cod sursa (job #2965345) | Cod sursa (job #1579227) | Cod sursa (job #997181) | Cod sursa (job #1501193) | Cod sursa (job #3237853)
#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 << x;
fin.close();
fout.close();
return 0;
}