Pagini recente » Cod sursa (job #2256970) | Cod sursa (job #2246267) | Cod sursa (job #878644) | Cod sursa (job #2977335) | Cod sursa (job #2863508)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long xx, yy;
int A, N;
void invers_modular(int a, int b, long long &x, long long &y)
{
if (b == 0){
x = 1;
y = 0;
}else{
long long x0, y0;
invers_modular(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
}
}
int main() {
fin >> A >> N;
invers_modular(A, N, xx, yy);
if (xx <= 0){
xx = N + xx % N;
}
fout << xx << '\n';
return 0;
}