function sum_of_mul_3_5(n) {
const max_3 = Math.floor((n - 1) / 3);
const max_5 = Math.floor((n - 1) / 5);
const max_15 = Math.floor((n - 1) / 15);
const total_3 = (3 * max_3 * (max_3 + 1)) / 2;
const total_5 = (5 * max_5 * (max_5 + 1)) / 2;
const total_15 = (15 * max_15 * (max_15 + 1)) / 2;
console.log(total_3 + total_5 - total_15);
}
sum_of_mul_3_5(1000000000);
233333333166666700
The output is not correct.
Using c++
long
data type, the correct answer is:
233333333166666668
How do I increase the max value of javascript Number
data type so that the function sum_of_mul_3_5
will output the correct result?