Pagini recente » Cod sursa (job #965983) | Cod sursa (job #1636591) | Cod sursa (job #2054408) | Cod sursa (job #2978071) | Cod sursa (job #1268503)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long T, i, a, b, c, D, n;
void euclid( long long &x, long long &y, long long a, long long b){
if( b == 0){
x = 1;
y = 0;
}
else{
euclid(x, y , b, a % b);
long long aux = x;
x = y;
y = aux - (a / b) * y;
}
}
int main()
{
fin >> a >> n;
long long x = 0, y;
euclid(x,y, a, n);
if(x <= 0)
x = n + x % n;
fout << x;
return 0;
}