-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathIntGroup.cpp
More file actions
42 lines (31 loc) · 728 Bytes
/
IntGroup.cpp
File metadata and controls
42 lines (31 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <immintrin.h>
#include "IntGroup.h"
using namespace std;
IntGroup::IntGroup(int size) {
this->size = size;
subp = (Int *)malloc(size * sizeof(Int));
}
IntGroup::~IntGroup() {
free(subp);
}
void IntGroup::Set(Int *pts) {
ints = pts;
}
// Compute modular inversion of the whole group
void IntGroup::ModInv() {
Int newValue;
Int inverse;
subp[0].Set(&ints[0]);
for (int i = 1; i < size; i++) {
subp[i].ModMulK1(&subp[i - 1], &ints[i]);
}
// Do the inversion
inverse.Set(&subp[size - 1]);
inverse.ModInv();
for (int i = size - 1; i > 0; i--) {
newValue.ModMulK1(&subp[i - 1], &inverse);
inverse.ModMulK1(&ints[i]);
ints[i].Set(&newValue);
}
ints[0].Set(&inverse);
}