Share via


BigInteger.ModPow Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Performs modulus division on a number raised to the power of another number.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

Syntax

'Declaration
Public Shared Function ModPow ( _
    value As BigInteger, _
    exponent As BigInteger, _
    modulus As BigInteger _
) As BigInteger
public static BigInteger ModPow(
    BigInteger value,
    BigInteger exponent,
    BigInteger modulus
)

Parameters

Return Value

Type: System.Numerics.BigInteger
The remainder after dividing valueexponent by modulus.

Exceptions

Exception Condition
DivideByZeroException

modulus is zero.

ArgumentOutOfRangeException

exponent is negative.

Remarks

The ModPow method evaluates the following expression:

(baseValue ^ exponent) Mod modulus

To perform exponentiation on BigInteger values without modulus division, use the Pow method.

Examples

The following example provides a simple illustration of calling the ModPow method.

Imports System.Numerics

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim number As BigInteger = 10
      Dim exponent As Integer = 3
      Dim modulus As BigInteger = 30
      outputBlock.Text += String.Format("({0}^{1}) Mod {2} = {3}", _
                        number, exponent, modulus, _
                        BigInteger.ModPow(number, exponent, modulus)) + vbCrLf 
   End Sub
End Module
' The example displays the following output:
'       (10^3) Mod 30 = 10      
using System;
using System.Numerics;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      BigInteger number = 10;
      int exponent = 3;
      BigInteger modulus = 30;
      outputBlock.Text += String.Format("({0}^{1}) Mod {2} = {3}",
                        number, exponent, modulus,
                        BigInteger.ModPow(number, exponent, modulus)) + "\n";
   }
}
// The example displays the following output:
//      (10^3) Mod 30 = 10

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.