Pagini recente » Cod sursa (job #1797082) | Cod sursa (job #2412868) | Cod sursa (job #2350628) | Cod sursa (job #3133380) | Cod sursa (job #1496974)
#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 - (a/b)*y;
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int n,a;
scanf("%d %d", &n, &a);
long long x, y;
euclid(n,a,x,y);
if(x < 0)
x = n + x % n;
printf("%d\n", x);
return 0;
}