The `modPow` method in Dart returns this integer raised to the power of an exponent modulo a modulus.
The syntax of int.modPow() method is:
int modPow(int exponent int modulus)
This modPow() method of int returns this integer to the power of exponent modulo modulus.
Parameter | Optional/Required | Description |
---|---|---|
exponent | required | The exponent to raise this integer to. |
modulus | required | The modulus with which to take the result modulo. |
int.modPow() returns value of type int
.
In this example,
base
to 5, exponent
to 3, and modulus
to 7.base
raised to the power of exponent
modulo modulus
using the modPow()
method.void main() {
int base = 5;
int exponent = 3;
int modulus = 7;
int result = base.modPow(exponent, modulus);
print('Result of $base^$exponent mod $modulus: $result');
}
Result of 5^3 mod 7: 6
In this example,
base
to 7, exponent
to 2, and modulus
to 11.base
raised to the power of exponent
modulo modulus
using the modPow()
method.void main() {
int base = 7;
int exponent = 2;
int modulus = 11;
int result = base.modPow(exponent, modulus);
print('Result of $base^$exponent mod $modulus: $result');
}
Result of 7^2 mod 11: 5
In this example,
base
to 3, exponent
to 4, and modulus
to 5.base
raised to the power of exponent
modulo modulus
using the modPow()
method.void main() {
int base = 3;
int exponent = 4;
int modulus = 5;
int result = base.modPow(exponent, modulus);
print('Result of $base^$exponent mod $modulus: $result');
}
Result of 3^4 mod 5: 1
In this Dart tutorial, we learned about modPow() method of int: the syntax and few working examples with output and detailed explanation for each example.