Pagini recente » Cod sursa (job #1704937) | Cod sursa (job #2659487) | Cod sursa (job #605920) | Cod sursa (job #345390) | Cod sursa (job #1868667)
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n,x,y,d;
void euclid_extins(int a,int b,int &d,int &x,int &y)
{
if(b==0)
{
d=a;
x=1;
y=0;
}
else
{
int x0,y0;
euclid_extins(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
f>>a>>n;
euclid_extins(a,n,d,x,y);
if(x<=0)
x=n+x%n;
g<<x;
return 0;
}