Your upper limit (1000000) needs to come from runtime (user input/file), otherwise you could create a C++ template program to compute the answer at compile time. Also, you might be interested in the Benchmarks Game:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
...where it looks like GCC C++ beats GraalVM in all the tests.