Pagini recente » Cod sursa (job #1062572) | Cod sursa (job #2985923) | Cod sursa (job #2351466) | Cod sursa (job #2249511) | Cod sursa (job #1689311)
#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;
}