Pagini recente » Profil NicuV | Cod sursa (job #2018548) | Cod sursa (job #1461874) | Statistici Santa David (Meinster) | Cod sursa (job #1685845)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n, k;
void euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
int xx = 0, yy = 0;
euclid(b, a%b, xx, yy);
x = yy;
y = xx - (a/b)*yy;
}
int main()
{
int x = 0, y = 0;
f >> n >> k;
euclid(n, k, x, y);
if (x <= 0)
x = (x+k)%k;
g << x;
return 0;
}