Pagini recente » Cod sursa (job #1530985) | Cod sursa (job #3285669)
#include <bits/stdc++.h>
#define DIM 100001
#define int long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int Q, a, b, c, d, x, y, MOD;
void Modular_Inverse(int a, int b, int &d, int &x, int &y){
if(!b){
d = a;
x = 1;
y = 1;
}
else {
int x1, y1;
Modular_Inverse(b, a % b, d, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int32_t main(){
Q = 1;
while(Q--){
fin >> a >> MOD;
Modular_Inverse(a, MOD, d, x, y);
while(x < 0)
x += MOD;
fout << x << "\n";
}
}