Pagini recente » Cod sursa (job #312777) | Cod sursa (job #896210) | Cod sursa (job #75942) | Cod sursa (job #2979335) | Cod sursa (job #2500260)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int modulo;
int cmmdc(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}else{
int ans = cmmdc(b, a % b, x, y);
int xPrim = x, yPrim = y;
x = yPrim % modulo;
y = (xPrim - (a / b) * yPrim) % modulo;
}
}
int main()
{
int n, m, x, y, ans;
in >> n >> m;
modulo = m;
ans = cmmdc(n, m, x, y);
out << x;
return 0;
}