Pagini recente » Cod sursa (job #2762721) | Cod sursa (job #540877) | Cod sursa (job #3002493) | Cod sursa (job #2789539) | Cod sursa (job #2745561)
#include <fstream>
using namespace std;
void euclid(int a, int b, int &x, int &y, int &d)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
return;
}
int xx, yy, q = a / b;
euclid(b, a % b, xx, yy, d);
x = yy;
y = xx - yy * q;
}
int main()
{
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int a,n,x,y,d;
cin>>a>>n;
euclid(a,n,x,y,d);
cout<<(n+x%n)%n;
return 0;
}