Pagini recente » Cod sursa (job #1498915) | Cod sursa (job #2199275) | Cod sursa (job #1674475) | Cod sursa (job #76597) | Cod sursa (job #1412354)
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll a, b, x, y;
ll euclid(ll a, ll b, ll &x, ll &y)
{
if (b==0)
{
x=1;
y=0;
return a;
}
else
{
ll x0, y0, d;
d=euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
}
int main()
{
f>>a>>b;
euclid(a,b,x,y);
while (x<0) x+=b;
g<<x<<'\n';
return 0;
}