Pagini recente » Cod sursa (job #1540992) | Cod sursa (job #2901360) | Cod sursa (job #3131475) | Cod sursa (job #2771776) | Cod sursa (job #1645018)
#include<fstream>
#include<cstring>
#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;
}