Pagini recente » Cod sursa (job #2828083) | Cod sursa (job #2234786) | Cod sursa (job #1315117) | Cod sursa (job #27925) | Cod sursa (job #2453548)
//ALEXANDRU MICLEA
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>
using namespace std;
#include <fstream>
ifstream cin("inversmodular.in"); ofstream cout("inversmodular.out");
void euclid_ext(long long a, long long b, long long& d, long long& x, long long& y) {
if (b == 0) {
d = a;
x = 1; y = 0;
}
else {
long long x0, y0;
euclid_ext(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
long long a, b, d, x, y;
cin >> a >> b;
euclid_ext(a, b, d, x, y);
x = (x % b + b) % b;
cout << x;
return 0;
}