Pagini recente » Cod sursa (job #160358) | Cod sursa (job #134157) | Cod sursa (job #1477720) | Cod sursa (job #2728299) | Cod sursa (job #1495283)
#include <cstdio>
using namespace std;
void euclid(const int a, const 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 - (a / b)*y;
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int n,a;
scanf("%d %d", &a, &n);
long long x, y;
euclid(a,n,x,y);
if(x < 0)
x = n + x % n;
printf("%lld\n", x);
return 0;
}