Today, we see a mention of this in the tech group: the sum of numbers that are divisible by 3 or 5 within 1000. It is interesting to see the solution two, the beginning is quite confused, and then thought, and then by people pointing, feel the Enlightenment.
The first solution is very common, that is, 1000 of the number are traversed once, as long as there is division 3 or divisible by 5 of the number, add it up, and finally get a total sum.
What interests me is the second solution, where the mathematical arithmetic progression is cleverly applied.
The arithmetic progression of a tolerance for the preceding paragraph is:
The second method uses the first step (A1+an)/3*3, so it becomes the 3* (1+333) *333/2, which adds up all the items that divide 3.
Similarly, in sum (Math.floor (input-1)/5) *5, add up all items that can divide 5 within 1000, and eventually divide 3 and divide 5 with duplicate numbers, such as 15, and then subtract the repetition by the number 15, You can get the sum of numbers that are divisible by 3 or 5 within 1000.
About the JS implementation of 1000 or 3 or 5 divisible by the number of the sum of the contents of the content will be introduced to everyone, I hope to help!