The solutions are passing because the timelimit/tesetcases are not strict enough. The only trick in these brute force solutions is to use integers inistead of long long for accumulating (possibly a time win of 50%). Only when the integer might overflow a long long is used to store the complete sum.