Cod sursa(job #3376620)

Utilizator popescu_georgePopescu George popescu_george Data 18 noiembrie 2026 17:27:07
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.32 kb
#include<fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
void A(int a,int b,int &d,int &x,int &y)
{
	if(b) {
		int e,f;
		A(b,a%b,d,e,f),x=f,y=e-a/b*f;
	} else
		d=a,x=1,y=0;
}
int main()
{
	int a,b,d,x,y;
	return cin>>a>>b,A(a,b,d,x,y),cout<<(x<0?b+x%b:x),0;
}