Pagini recente » Cod sursa (job #462115) | Cod sursa (job #2865384) | Cod sursa (job #1931291) | Cod sursa (job #2052675) | Cod sursa (job #664277)
Cod sursa(job #664277)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long x,y;
int a,n;
void euclext (long long &x, long long &y, int a, int b)
{
long long aux;
if (b==0)
{
x = 1;
y = 0;
}
else
{
euclext(x,y,b,a%b);
aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main ()
{
f>>a>>n;
euclext(x,y,a,n);
if (x<=0)
x=n+x%n;
g<<x<<'\n';
return 0;
}