Pagini recente » Cod sursa (job #2005587) | Cod sursa (job #679611) | Cod sursa (job #1125522) | Cod sursa (job #1914809) | Cod sursa (job #720790)
Cod sursa(job #720790)
#include <fstream>
using namespace std;
inline void euclid(int a, int b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
long long x0, y0;
euclid (b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
int a, n;
long long x, y;
ifstream f("inversmodular.in");
f>>a>>n;
f.close();
euclid(a, n, x, y);
if (x<=0)
x += n;
ofstream g("inversmodular.out");
g<<x<<"\n";
g.close();
return 0;
}