Pagini recente » Cod sursa (job #2169950) | Cod sursa (job #2125248) | Cod sursa (job #1083333) | Cod sursa (job #328441) | Cod sursa (job #754709)
Cod sursa(job #754709)
#include <fstream>
#include <cstdlib>
using namespace std;
inline void gcd(int a, int b, int& x, int& y, int& d)
{
if(!b)
{
x=1;
y=0;
d=a;
}
else {
int x0, y0;
gcd(b, a%b, x0, y0, d);
x=y0;
y=x0 - (a/b)*y0;
}
}
int main()
{
int A, N, x, y, d;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
in>>A>>N;
gcd(A, N, x, y, d);
if(x < 0)
x+=N;
out<<x<<'\n';
return EXIT_SUCCESS;
}