#include <iostream>
#include <stdint.h>
int main() {
const auto n_hashbits = 5;
auto magic = (1ull << 50) + (2ull << 39) + (3ull << 30) + (5ull << 21);
std::cout << "Magic: " << std::hex << magic << std::dec << "\n";
for (auto square : {9, 11, 20, 29, 38}) {
uint64_t bitboard = 1ull << square;
uint64_t index = magic * bitboard;
index >>= (64 - n_hashbits);
std::cout << square << " => " << index << "\n";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW50Lmg+CgppbnQgbWFpbigpIHsKCWNvbnN0IGF1dG8gbl9oYXNoYml0cyA9IDU7CglhdXRvIG1hZ2ljID0gKDF1bGwgPDwgNTApICsgKDJ1bGwgPDwgMzkpICsgKDN1bGwgPDwgMzApICsgKDV1bGwgPDwgMjEpOwoJc3RkOjpjb3V0IDw8ICJNYWdpYzogIiA8PCBzdGQ6OmhleCA8PCBtYWdpYyA8PCBzdGQ6OmRlYyA8PCAiXG4iOwoJCglmb3IgKGF1dG8gc3F1YXJlIDogezksIDExLCAyMCwgMjksIDM4fSkgewoJCXVpbnQ2NF90IGJpdGJvYXJkID0gMXVsbCA8PCBzcXVhcmU7CgkJdWludDY0X3QgaW5kZXggPSBtYWdpYyAqIGJpdGJvYXJkOwoJCWluZGV4ID4+PSAoNjQgIC0gbl9oYXNoYml0cyk7CgkJc3RkOjpjb3V0IDw8IHNxdWFyZSA8PCAiID0+ICIgPDwgaW5kZXggPDwgIlxuIjsKCX0KfQ==