Pagini recente » Cod sursa (job #1305426) | Cod sursa (job #2567906) | Cod sursa (job #783799) | Cod sursa (job #582367) | Cod sursa (job #720789)
Cod sursa(job #720789)
#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
{
int 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;
}