Cod sursa(job #432777)

Utilizator Teodor94Teodor Plop Teodor94 Data 2 aprilie 2010 19:17:01
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<cstdio>

void euclid(int a,int b,int &x,int &y,int &d)
{
	if (b==0)
	{
		x=1;
		y=0;
		d=a;
		return;
	}
	int x1,y1;
	euclid(b,a%b,x1,y1,d);
	x=y1;
	y=x1-(a/b)*y1;
}

int main()
{
	freopen("inversmodular.in","r",stdin);
	freopen("inversmodular.out","w",stdout);
	int a,n,x,y,d;
	scanf("%d%d",&a,&n);
	euclid(a,n,x,y,d);
	for (;x<0;x+=n);
	printf("%d\n",x);
	return 0;
}