コード例 #1
0
unsigned int getMultiplicativeInverseUsingExtendedEuclides(unsigned int x,unsigned int y){
	int *ee=extendedEuclides(x,y);
	if(ee[1]<0){
		return y-((ee[1]*-1)%y);	
	}
	return (ee[1]%y);
}
コード例 #2
0
ファイル: extEuc.cpp プロジェクト: Neverous/xivlo08-11
int main ( void )
{
	scanf ( "%d %d", & first, & second );
	result = extendedEuclides ( first, second ); // Zakładam, że first > second
	printf ( "%d %d %d\n", result . x, result . y, result . gcd );
	return 0;
}
コード例 #3
0
ファイル: extEuc.cpp プロジェクト: Neverous/xivlo08-11
Gcd extendedEuclides ( int first, int second )
{
	Gcd result;
	int tmp;
	result . gcd = second;
	if ( first % second == 0 )
		return result;

	result = extendedEuclides ( second, first % second );
	tmp = result . x;
	result . x = result . y;
	result . y = tmp - result . y * ( first / second );

	return result;
}
コード例 #4
0
int *extendedEuclides(unsigned int x, unsigned int y){//this function return array that contain multiplicative inverse of x in Z/y and viseversa multiplicative inverse of y in Z/x	
	int quotient=x/y;
	unsigned int remainder=x%y;
	int *last=(int *)malloc(sizeof(int)*4);//here was exprecion of inverse multiplicative (1=ax+by, where a is inverse multiplicative of x in Z/y and b is inverse multiplicative of y in Z/x)
	if(remainder==1){
		last[0]=x;
		last[1]=1;
		last[2]=y;
		last[3]=-1*quotient;
		return last;
	}
	last=extendedEuclides(y,remainder);
	int auxiliary;
	last[0]=x;
	auxiliary=last[1];
	last[1]=last[3];
	last[2]=y;
	last[3]=last[3]*-1*quotient+auxiliary;
	return last;
}