예제 #1
0
pair extendedgcd(long long int a, long long int b){
	if (b == 0){
		pair p = {1, 0};
		return p;
	} else {
		pair p = {a / b, a % b};
		pair q = extendedgcd(b, p.b);
		pair r = {q.b, q.a - p.a * q.b};
		return r;
	}
}
예제 #2
0
int extendedgcd(int a,int b,int *x,int *y)// Computing Multiplicative Inverse
 {
 if(a==0)
   {
     *x=0;
     *y=1;
     return b;
    }
 else
    {
      int x1,y1,gcd;
      gcd= extendedgcd(b%a,a,&x1,&y1);
      *x=y1-(b/a) * x1;
      *y=x1;
      return gcd;
   }
 }
예제 #3
0
int main()
 {
 int a,b,result,x,y;
 printf("Enter the number: ");
 scanf("%d",&a);
 printf("Enter the size of the set:");
 scanf("%d",&b);
 if(a<0) // Checking for negative numbers
   {
     a+=b;
   }
 result=extendedgcd(a,b,&x,&y);
 if(x<0)
   {
     x+=b;
   }
 printf("The Multiplicative Inverse is %d \n",x);
 additive_I(a,b);
 return 0;
 }
예제 #4
0
long long int modMultInverse(long long int n, long long int mod){
	return extendedgcd(n, mod).a;
}