You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/math/combinatorics.md
+9
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,14 @@ int64_t fastpow(int64_t a, int64_t b) {
27
27
```
28
28
Efficiently computes $a^b \mod \text{md}$ using recursive exponentiation by squaring. This function operates in $O(\log b)$ time, making it suitable for handling large exponents.
29
29
30
+
#### `inverse`
31
+
```cpp
32
+
auto inverse = [&](int64_t num) -> int64_t {
33
+
return fastpow(num, md - 2);
34
+
};
35
+
```
36
+
Computes the modular inverse of a number $\( \text{num} \mod \text{md} \)$ using Fermat's Little Theorem. This method is efficient and operates in $\( O(\log \text{md}) \)$.
37
+
30
38
### 3. Precomputations
31
39
#### Factorial Table Construction
32
40
```cpp
@@ -42,6 +50,7 @@ void buildFactorial() {
42
50
```
43
51
Precomputes factorial values up to a maximum limit (`MXN`) modulo `md`. This precomputation allows for constant-time access to factorial values, which are used extensively in combinatorics calculations.
0 commit comments