Pagini recente » Cod sursa (job #2398841) | Cod sursa (job #1757731) | Cod sursa (job #2143030) | Cod sursa (job #2274980) | Cod sursa (job #2228581)
#include <bits/stdc++.h>
using namespace std;
void euclid_extins(long long a, long long b, long long &x, long long &y, long long &d){
if(b == 0){
x = 1;
y = 0;
d = a;
return ;
}
euclid_extins(b, a%b, x, y, d);
long long newx = y;
long long newy = x - y*(a/b) ;
x = newx;
y = newy;
}
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int main()
{
long long n, a, x, y, d;
fin >> a >> n;
euclid_extins(a, n, x, y, d);
x %= n;
if(x < 0) x += n;
fout << x;
return 0;
}