Skip to content

Commit

Permalink
Add nim product
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeletWithoutEgg committed Feb 6, 2024
1 parent ec4903a commit 75b7ad7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions codes/Misc/NimProd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#define rep(i, r) for (int i = 0; i < r; i++)
struct NimProd {
llu bit_prod[64][64]{}, prod[8][8][256][256]{};
NimProd() {
rep(i, 64) rep(j, 64) if (i & j) {
int a = lowbit(i & j);
bit_prod[i][j] = bit_prod[i ^ a][j] ^
bit_prod[(i ^ a) | (a-1)][(j ^ a) | (i & (a-1))];
} else bit_prod[i][j] = 1ULL << (i | j);
rep(e, 8) rep(f, 8) rep(x, 256) rep(y, 256)
rep(i, 8) if (x >> i & 1) rep(j, 8) if (y >> j & 1)
prod[e][f][x][y] ^= bit_prod[e * 8 + i][f * 8 + j];
}
llu operator()(llu a, llu b) const {
llu res = 0;
rep(e, 8) rep(f, 8)
res ^= prod[e][f][a >> (e * 8) & 255][b >> (f * 8) & 255];
return res;
}
};
3 changes: 3 additions & 0 deletions pdf/content.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,6 @@
- name: Montgomery
path: Montgomery.cpp
verified: 012165f
- name: Nim Product
path: NimProd.cpp
verified:

0 comments on commit 75b7ad7

Please sign in to comment.