Pagini recente » Cod sursa (job #1875541) | Cod sursa (job #2245045) | Cod sursa (job #1956644) | Cod sursa (job #2369632) | 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;
}