Pagini recente » Cod sursa (job #841295) | Cod sursa (job #2221166) | Cod sursa (job #1811883) | Cod sursa (job #937376) | Cod sursa (job #1428327)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n ,a,b,i,d,c,q,r;
void invmod(long long &x, long long &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
invmod(x, y, b, a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
long long x,y;
f>>a>>b;
x=0;
invmod(x,y,a,b);
if (x<= 0)
x= b+x%b;
g<<x;
return 0;
}