Ejemplo n.º 1
0
 /// <summary>
 /// Determines if the specified value is coprime to the specified prime number.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="primeValue">The prime number to test against.</param>
 /// <returns>True if the value is coprime to the prime number, otherwise, false.</returns>
 public static bool IsCoprimeToPrime(this int value, int primeValue)
 {
     if (primeValue < 2)
     {
         throw new ArgumentOutOfRangeException("primeValue");
     }
     return(UintExtensions.IsCoprimeToPrime(AbsUint(value), (uint)primeValue));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Compute the mod of a number raised to the specified power.
        /// </summary>
        /// <remarks>Overflow safe for all input values. </remarks>
        /// <param name="b">The base number.</param>
        /// <param name="e">The exponent applied to the base number.</param>
        /// <param name="m">The modulo value.</param>
        /// <returns>The mod of the base number raised to the specified power.</returns>
        public static int ModPow(int b, int e, int m)
        {
            if (e < 0 || m < 1)
            {
                return(-1);
            }
            uint bu     = AbsUint(b);
            int  result = (int)UintExtensions.ModPow(bu, (uint)e, (uint)m);

            if (((e & 1) == 0) && (b < 0))
            {
                result = -result;
            }
            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Computes the greatest common divisor of two values.
 /// </summary>
 /// <param name="value1">The value.</param></param></param>
 /// <param name="value2">The other value.</param>
 /// <returns>The greatest common divisor of the two values.</returns>
 public static int Gcd(this int value1, int value2)
 {
     return((int)UintExtensions.Gcd(AbsUint(value1), AbsUint(value2)));
 }