BigInteger.ModPow(BigInteger, BigInteger, BigInteger) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Performs modulus division on a number raised to the power of another number.
public:
static System::Numerics::BigInteger ModPow(System::Numerics::BigInteger value, System::Numerics::BigInteger exponent, System::Numerics::BigInteger modulus);
public static System.Numerics.BigInteger ModPow(System.Numerics.BigInteger value, System.Numerics.BigInteger exponent, System.Numerics.BigInteger modulus);
static member ModPow : System.Numerics.BigInteger * System.Numerics.BigInteger * System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function ModPow (value As BigInteger, exponent As BigInteger, modulus As BigInteger) As BigInteger
- value
- BigInteger
The number to raise to the exponent
power.
- exponent
- BigInteger
The exponent to raise value
by.
- modulus
- BigInteger
The number by which to divide value
raised to the exponent
power.
The remainder after dividing value
exponent by modulus
.
modulus
is zero.
exponent
is negative.
The following example provides a simple illustration of calling the ModPow method.
using System;
using System.Numerics;
public class Class1
{
public static void Main()
{
BigInteger number = 10;
int exponent = 3;
BigInteger modulus = 30;
Console.WriteLine("({0}^{1}) Mod {2} = {3}",
number, exponent, modulus,
BigInteger.ModPow(number, exponent, modulus));
}
}
// The example displays the following output:
// (10^3) Mod 30 = 10
open System.Numerics;
let number = 10I;
let exponent = 3;
let modulus = 30I;
printfn $"({number}^{exponent}) Mod {modulus} = {BigInteger.ModPow(number, exponent, modulus)}"
// The example displays the following output:
// (10^3) Mod 30 = 10
Imports System.Numerics
Module Example
Public Sub Main()
Dim number As BigInteger = 10
Dim exponent As Integer = 3
Dim modulus As BigInteger = 30
Console.WriteLine("({0}^{1}) Mod {2} = {3}", _
number, exponent, modulus, _
BigInteger.ModPow(number, exponent, modulus))
End Sub
End Module
' The example displays the following output:
' (10^3) Mod 30 = 10
The ModPow method evaluates the following expression:
(baseValue ^ exponent) Mod modulus
To perform exponentiation on BigInteger values without modulus division, use the Pow method.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: