Pagini recente » Cod sursa (job #3182925) | Cod sursa (job #6212) | Cod sursa (job #974108) | Cod sursa (job #802018) | Cod sursa (job #3167897)
#include <iostream>
#include <fstream>
using namespace std;
// #define cin fin
// #define cout fout
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(long long a, long long b, long long& x, long long& y);
int main()
{
long long a, n, x, y;
cin >> a >> n;
euclid(a, n, x, y);
cout << x;
return 0;
}
void euclid(long long a, long long b, long long& x, long long& y)
{
if(b == 0)
{
y = 0;
x = 1;
}
else
{
long long x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}