Pagini recente » Cod sursa (job #3193009) | Cod sursa (job #2870090) | Cod sursa (job #227836) | Diferente pentru implica-te/arhiva-educationala intre reviziile 6 si 5 | Cod sursa (job #1512671)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
int main() {
int a, b;
fin >> a >> b;
fout << mul_inv(a,b);
}