Cod sursa(job #2848143)

Utilizator HaliM28Haliga Mihnea HaliM28 Data 12 februarie 2022 10:32:45
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int s(int a, int b, int& x, int& y)
{
	if (b == 0) { x = 1, y = 0; return a; }
		int x0, y0,d;
		d=s(b, a % b, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
		return d;
}
int main()
{
	int a, n;
	fin >> a >> n;
		int d,x,y;
	d = s(a, n, x, y);
	while (x < 0)
		x += n;
	fout << x;
	return 0;
}