Pagini recente » Cod sursa (job #2352379) | Cod sursa (job #2047919) | Cod sursa (job #2391479) | Cod sursa (job #1667929) | Cod sursa (job #1401844)
#include <stdio.h>
using namespace std;
void inv(int a, int b, long long &x, long long &y){
if(!b){
x = 1;
y = 0;
}else{
inv(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 A, N;
long long x = 0, y;
scanf("%d %d", &A, &N);
inv(A, N, x, y);
if(x < 0)
x = N + x % N;
printf("%d\n", x);
return 0;
}