Pagini recente » Cod sursa (job #703715) | Cod sursa (job #1338389) | Cod sursa (job #570711) | Cod sursa (job #2276096) | Cod sursa (job #1854635)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,n,d,x,y,c;
int euclid(int a,int b,int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
int x0,y0;
d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main(){
fin >> a >> n;
d = euclid(a,n,x,y);
if(x < 0)
x = n + x % n;
fout << x;
return 0;
}