Pagini recente » Cod sursa (job #3248549) | Cod sursa (job #1335802) | Cod sursa (job #179215) | Cod sursa (job #1363666) | 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;
}