Pagini recente » Cod sursa (job #2946519) | Cod sursa (job #2589083) | Cod sursa (job #2253950) | Cod sursa (job #760904) | Cod sursa (job #1497701)
#include <cstdio>
using namespace std;
void euclid(int a, int b, long long &x, long long &y){
if(not b){
x = 1;
y = 0;
return;
}
euclid(b,a%b,x,y);
long long aux = x;
x = y;
y = aux - y * (a/b);
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int a,n;
long long x,y;
scanf("%d %d", &a, &n);
euclid(a,n,x,y);
if(x < 0)
x = n + x % n;
printf("%lld", x);
return 0;
}