Pagini recente » Cod sursa (job #573654) | Cod sursa (job #2074113) | Cod sursa (job #1737404) | Cod sursa (job #832452) | Cod sursa (job #2596664)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n;
int x, y, x00, y00;
void cmmdc(int a, int b);
int main()
{
fin >> a >> n;
cmmdc(n, a);
while(y < 0) y += n;
fout << y;
return 0;
}
void cmmdc(int a, int b){
if(!b){
x = 1;
y = 0;
return;
}
else{
cmmdc(b, a % b);
x00 = y;
y00 = x - y * (a / b);
x = x00; y = y00;
}
}