Exemple #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 long value, long primeValue)
 {
     if (primeValue < 2)
     {
         throw new ArgumentOutOfRangeException("primeValue");
     }
     return(UlongExtensions.IsCoprimeToPrime(AbsUlong(value), (ulong)primeValue));
 }
Exemple #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 long ModPow(long b, long e, long m)
        {
            if (e < 0 || m < 1)
            {
                return(-1);
            }
            ulong bu     = AbsUlong(b);
            long  result = (long)UlongExtensions.ModPow(bu, (ulong)e, (ulong)m);

            if (((e & 1) == 0) && (b < 0))
            {
                result = -result;
            }
            return(result);
        }
Exemple #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 long Gcd(this long value1, long value2)
 {
     return((long)UlongExtensions.Gcd(AbsUlong(value1), AbsUlong(value2)));
 }