Pagini recente » Cod sursa (job #60945) | Cod sursa (job #1375881) | Cod sursa (job #392449) | Cod sursa (job #2420232) | Cod sursa (job #3167869)
#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 % n;
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;
}
}