Pagini recente » Cod sursa (job #1052847) | Cod sursa (job #281797) | Cod sursa (job #2162793) | Cod sursa (job #1018612) | Cod sursa (job #2105927)
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a,n;
long long x,y;
void euclid(long long &x,long long &y, int a,int b)
{
if(!b)
{
x=1;
y=0;
}
else
{
euclid(x,y,b,a%b);
long long aux = x;
x=y;
y= aux- y* (a/b);
}
}
int main()
{
in>>a>>n;
euclid(x,y,a,n);
if(x <= 0)
x = (x+n) %n;
out<<x;
return 0;
}