mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
clang-format and clang-tidy fixes for 2ad5420a
This commit is contained in:
parent
0e1e441ab3
commit
b9cdab9354
@ -5,7 +5,8 @@
|
|||||||
* @details To calculate division of two numbers under modulo p
|
* @details To calculate division of two numbers under modulo p
|
||||||
* Modulo operator is not distributive under division, therefore
|
* Modulo operator is not distributive under division, therefore
|
||||||
* we first have to calculate the inverse of divisor using
|
* we first have to calculate the inverse of divisor using
|
||||||
* [Fermat's little theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem)
|
* [Fermat's little
|
||||||
|
theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem)
|
||||||
* Now, we can multiply the dividend with the inverse of divisor
|
* Now, we can multiply the dividend with the inverse of divisor
|
||||||
* and modulo is distributive over multiplication operation.
|
* and modulo is distributive over multiplication operation.
|
||||||
* Let,
|
* Let,
|
||||||
@ -71,7 +72,8 @@ namespace math {
|
|||||||
*/
|
*/
|
||||||
uint64_t mod_division(uint64_t a, uint64_t b, uint64_t p) {
|
uint64_t mod_division(uint64_t a, uint64_t b, uint64_t p) {
|
||||||
uint64_t inverse = power(b, p - 2, p) % p; /// Calculate the inverse of b
|
uint64_t inverse = power(b, p - 2, p) % p; /// Calculate the inverse of b
|
||||||
uint64_t result = ((a%p)*(inverse%p))%p; /// Calculate the final result
|
uint64_t result =
|
||||||
|
((a % p) * (inverse % p)) % p; /// Calculate the final result
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} // namespace modular_division
|
} // namespace modular_division
|
||||||
|
Loading…
x
Reference in New Issue
Block a user