Pagini recente » Cod sursa (job #1907662) | Rating Bornaz Sebastian (cackle) | Cod sursa (job #1907887) | Cod sursa (job #2606528) | Cod sursa (job #2816662)
#include<bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(int a, int b, int &d, int &x, int &y)
{
if(b==0)
{
x=1;
y=0;
d=a;
}
else
{
int x0,y0;
euclid(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
int a,b,d,x,y;
f>>a>>b;
euclid(a,b,d,x,y);
while(x<0)
x+=b;
g<<x;
return 0;
}