Pagini recente » Cod sursa (job #1441019) | Cod sursa (job #1806345) | Cod sursa (job #2548951) | Cod sursa (job #2405847) | Cod sursa (job #2225167)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a, mod, x, y;
int euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int xx, yy, d;
d = euclid(b, a%b, xx, yy);
x = yy;
y = xx-(a/b)*yy;
return d;
}
int main() {
f >> a >> mod;
euclid(a, mod, x, y);
if (x < 0) x += mod;
g << x;
return 0;
}