Pagini recente » Monitorul de evaluare | Profil SKREFI | Cod sursa (job #815435) | Cod sursa (job #3333715) | Cod sursa (job #3350337)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclidExtins(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
int x0, y0;
int d = euclidExtins(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main(){
int a,n, x, y;
fin >> a >> n;
euclidExtins(a,n,x,y);
while(x < 0){
x += n;
}
fout << x;
return 0;
}