Pagini recente » Cod sursa (job #1562021) | Diferente pentru problema/mts intre reviziile 10 si 7 | Diferente pentru problema/hiperquery intre reviziile 29 si 22 | Diferente pentru problema/temple intre reviziile 10 si 4 | Cod sursa (job #1413527)
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
void invers(LL a, LL b, LL &x, LL &y){
if(!b){
x = 1;
y = 0;
return;
}
invers(b, a % b, x, y);
LL aux = x;
x = y;
y = aux - a/b * y;
}
int main()
{
LL a, n, x, y;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
fin >> a >> n;
invers(a, n, x, y);
if(x < 0)
x += n;
fout << x;
return 0;
}