The `modInverse` method in Dart returns the modular multiplicative inverse of this integer modulo the given modulus.
The syntax of int.modInverse() method is:
int modInverse(int modulus)
This modInverse() method of int returns the modular multiplicative inverse of this integer modulo modulus.
Parameter | Optional/Required | Description |
---|---|---|
modulus | required | The modulus value to compute the inverse. |
int.modInverse() returns value of type int
.
In this example,
num
with the value 3 and a modulus variable with the value 11.modInverse()
method with the modulus as the argument to compute the modular multiplicative inverse.void main() {
int num = 3;
int modulus = 11;
int inverse = num.modInverse(modulus);
print('Modular multiplicative inverse of $num modulo $modulus: $inverse');
}
Modular multiplicative inverse of 3 modulo 11: 4
In this example,
num
with the value 5 and a modulus variable with the value 12.modInverse()
method with the modulus as the argument to compute the modular multiplicative inverse.void main() {
int num = 5;
int modulus = 12;
int inverse = num.modInverse(modulus);
print('Modular multiplicative inverse of $num modulo $modulus: $inverse');
}
Modular multiplicative inverse of 5 modulo 12: 5
In this example,
num
with the value 7 and a modulus variable with the value 10.modInverse()
method with the modulus as the argument to compute the modular multiplicative inverse.void main() {
int num = 7;
int modulus = 10;
int inverse = num.modInverse(modulus);
print('Modular multiplicative inverse of $num modulo $modulus: $inverse');
}
Modular multiplicative inverse of 7 modulo 10: 3
In this Dart tutorial, we learned about modInverse() method of int: the syntax and few working examples with output and detailed explanation for each example.