Pagini recente » Cod sursa (job #671050) | Cod sursa (job #2671496) | Cod sursa (job #1745629) | Cod sursa (job #2561191) | Cod sursa (job #3156978)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int gcd(int a, int b, int &x, int &y){
if(!b){
x = 1;
y = 0;
return a;
}
int x0,y0;
int d = gcd(b,a % b,x0,y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
//cu alg euclid extins
int n,m,x,y,d;
fin >> n >> m;
d = gcd(m,n,x,y);
while(y < 0){
y += m;
}
fout << y;
return 0;
}