Skip to content

Commit 57cefdf

Browse files
committed
Allocate enough memory for factorials
1 parent 468c59d commit 57cefdf

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/algebra/factorial-modulo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ If you need to call the function multiple times, then you can do the precomputat
6363

6464
```cpp
6565
int factmod(int n, int p) {
66-
vector<int> f;
67-
f.push_back(1);
66+
vector<int> f(p);
67+
f[0] = 1;
6868
for (int i = 1; i < p; i++)
6969
f[i] = f[i-1] * i % p;
7070

0 commit comments

Comments
 (0)