Pagini recente » Cod sursa (job #1711376) | Cod sursa (job #762771) | Cod sursa (job #1338686) | Cod sursa (job #2575798) | Cod sursa (job #1882417)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclidExt(int a, int b, long long &x, long long &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
long long x0, y0, d;
d=euclidExt(b, a%b, x0, y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
int main()
{
int a, n;
fin>>a>>n;
long long x, y, d;
d=euclidExt(a, n, x, y);
if(x<=0)
x=n+x%n;
fout<<x;
}