Cod sursa(job #2960775)

Utilizator alexandru_ioan.06Alexandru Ioan alexandru_ioan.06 Data 4 ianuarie 2023 22:25:36
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>

using namespace std;
ifstream cin ("inversmodular.in");
ofstream cout ("inversmodular.out");

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

int main()
{
	long long x , n;
	cin >> x >> n;
	long long X , Y;
	Euclid(x , n , X , Y);
	while(x < 0)
        x += n;
	cout << X;
}