Pagini recente » Cod sursa (job #1063796) | Cod sursa (job #2953829) | Cod sursa (job #1525267) | Cod sursa (job #2989781) | Cod sursa (job #1689308)
#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;
}