Pagini recente » Cod sursa (job #1715055) | Cod sursa (job #1802801) | Cod sursa (job #2061186) | Cod sursa (job #2629887) | Cod sursa (job #1496977)
#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", &a, &n);
long long x, y;
euclid(n,a,x,y);
if(x < 0)
x = n + x % n;
printf("%d\n", x);
return 0;
}