How can I calculate division and modulo for integer numbers in C#?
Modulo Division operator % in C language can be used only with integer variables or constants.
For p = prime , b^(-1) mod p = b^(p - 2) mod p . You don't need any modular inverses from this. Just simplify the fraction: N or N^2+5 will be divisible by 2 and 3 . So divide them and then you have (a*b) mod P .
We use the % to denote this type of operator (it's the percentile operator). The modulus operator is added in the arithmetic operators in C, and it works between two available operands. It divides the given numerator by the denominator to find a result.
Here's an answer from the MSDN documentation.
When you divide two integers, the result is always an integer. For example, the result of 7 / 3 is 2. To determine the remainder of 7 / 3, use the remainder operator (%).
int a = 5; int b = 3; int div = a / b; //quotient is 1 int mod = a % b; //remainder is 2
There is also Math.DivRem
quotient = Math.DivRem(dividend, divisor, out remainder);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With