Cod sursa(job #2679788)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 1 decembrie 2020 14:45:57
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
//ALEXANDRU MICLEA

#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#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>
#include <assert.h>

using namespace std;
using ll = long long;

#include <fstream>
//ifstream cin("input.in"); ofstream cout("output.out");
ifstream cin("inversmodular.in"); ofstream cout("inversmodular.out");

//VARIABLES



//FUNCTIONS

void euclid(long long a, long long b, long long& d, long long& x, long long& y) {
	if (b == 0) {
		d = a;
		x = 1; y = 0;
	}

	long long x0, y0;
	euclid(b, a % b, d, x0, y0);
	x = y0;
	y0 = x0 - (a / b) * y0;
}

//MAIN

int main() {

	long long a, n, d, x, y;
	cin >> a >> n;

	euclid(a, n, d, x, y);

	x = (x % n + n) % n;
	cout << x;

	return 0;
}