Pagini recente » Cod sursa (job #2546154) | Cod sursa (job #1391700) | Cod sursa (job #480563) | Cod sursa (job #978935) | Cod sursa (job #1689304)
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
long long x, y;
int a,b;
void invers_modular(long long &x, long long &y, int a, int b)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
long long d;
invers_modular(x, y, b, a%b);
d = x;
x = y;
y = d - ( a / b )*y;
}
}
int main()
{
cin >> a >> b;
invers_modular(x, y, a, b);
if(x < 0)
x = b + x%b;
cout <<x;
return 0;
}