Pagini recente » Cod sursa (job #2376708) | Cod sursa (job #1521395) | Cod sursa (job #1847916) | Cod sursa (job #1032658) | Cod sursa (job #2048185)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int n, a;
void eucex(int a, int b, int& x, int& y, int& d)
{
if(!b)
{
d = a;
x = 1;
y = 0;
}
else
{
int xx, yy;
eucex(b, a%b, xx, yy, d);
x = yy;///!
y = xx - (a / b) * yy;///!
}
}
int main()
{
ios::sync_with_stdio(false);
fin >> a >> n;
int x, y, d;
eucex(a, n, x, y, d);
while(x < 0)
x += n;
fout << x << "\n";
return 0;
}