Cod sursa(job #2453548)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 4 septembrie 2019 13:24:02
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
//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;
}