Sorry, there's a typo in line 11: the first arg to `splitToTerms` should be `n-i`, not `n-1`. Unfortunately, the time limit for editing the post has passed. Correct program runs faster.
Regarding your other question, I suggest you use `getMonoTime` instead of `cpuTime` in threading situations.
