Pagini recente » Cod sursa (job #1015443) | Cod sursa (job #2131913) | Cod sursa (job #66457) | Cod sursa (job #1939978) | Cod sursa (job #3001267)
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int n, a;
void gcd(long long &x, long long &y, int a, int b){
if(!b){
x = 1, y = 0;
}
else{
gcd(x, y, b, a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
long long inv = 0, ins;
in >> a >> n;
gcd(inv, ins, a, n);
if(inv <= 0){
inv = n + inv % n;
}
out << inv;
return 0;
}