Pagini recente » Cod sursa (job #301493) | Cod sursa (job #2485276) | Cod sursa (job #1536347) | Cod sursa (job #904001) | Cod sursa (job #1262455)
#include <fstream>
using namespace std;
void gcd(int a, int b, int &x, int &y) {
if(!b) {
x = 1;
y = 0;
return;
}
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
int main() {
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
gcd(a, n, x, y);
if(x < 0)
x = n + x % n;
fout << x << '\n';
}