Modulo
std::array<int, 5> modulos{11, 107, 1013, 19211, 81727};
for (auto i = 0u; i < arr.size(); ++i) {
sum += arr[i] % modulos[i * 5 / arr.size()];
}
for (auto i = 0u; i < arr.size(); ++i) {
switch (i * 5 / arr.size()) {
case 0:
sum += arr[i] % 11;
break;
case 1:
sum += arr[i] % 107;
break;
case 2:
sum += arr[i] % 1013;
break;
case 3:
sum += arr[i] % 19211;
break;
case 4:
sum += arr[i] % 81727;
break;
}
}
* The benchmark is run under Apple Macbook Air M2.
* For the full benchmark code, please refer here.