Cod sursa(job #3121564)

Utilizator daristyleBejan Darius-Ramon daristyle Data 14 aprilie 2023 01:31:04
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;

ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

void extended_euclid(int a, int b, int &x, int &y) {
	if(!b){
		x = 1;
		y = 0;
	}else{
		int x0, y0;
		extended_euclid(b, a % b, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
	}
}

int main() {
	int a, n, x, y;
	fin >> a >> n;

	extended_euclid(a, n, x, y);

	fout << x << '\n';


	fin.close();
	fout.close();
	return 0;
}