Pagini recente » Cod sursa (job #1760311) | Cod sursa (job #378146) | Cod sursa (job #314136) | Cod sursa (job #2128398) | Cod sursa (job #1365665)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
inline 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() {
int a, n;
fin >> a >> n;
int x, y;
gcd(a, n, x, y);
x %= n;
while(x < 0)
x += n;
fout << x << '\n';
}