Pagini recente » Cod sursa (job #2523522) | Cod sursa (job #420371) | Cod sursa (job #56338) | Cod sursa (job #1901241) | Cod sursa (job #1197311)
#include <cstdio>
using namespace std;
int main()
{
int a, b, cat[32], x, y, nc, r, i;
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d%d", &a, &b);
nc = 0;
while(b!=0){
r = a%b;
cat[++nc] = a/b;
a = b;
b = r;
}
x = 1; y = 0;
for(i=nc; i>=1; i--){
r = x;
x = y;
y = r - cat[i]*y;
}
printf("%d\n", x);
return 0;
}