Meta:
Your C++ translation: ~277ms Your second version: ~2.34ms/round
Both D programs are translations of C++ programs.
LDC might do a better job with this.
I have developed those two programs using ldc2, so the usage of ldc2 is encouraged, and inlining is necessary for both programs. Generally don't use DMD for benchmark contests like this one.
Bye, bearophile