JS implements the sum of numbers divided by 3 or 5 in less than 1000, and js division
Today, we can see in the Technical Group that the sum of the numbers 3 or 5 divided by less than 1000 is calculated. The interesting solution is solution 2, which was quite confusing at the beginning. Later I thought about it and I thought it was too confusing.
The first solution is very common, that is, to traverse the number of less than 1000, as long as there is a total of 3 or a total of 5, it will add up, and finally get a total sum.
I am interested in the second solution. Here we use the mathematical arithmetic difference series.
The level of the first item of an equal-difference series with a tolerances is:
The first step of the second method is to use (a1 + an)/3*3, so it becomes 3*(1 + 333) * 333/2, this step adds up all the items except 3.
Similarly, sum (Math. in floor (input-1)/5) * 5, all the items that can be divided into 5 within 1000 can be added up and finally divided into 3 and 5 with repeated numbers, for example, if you divide the number by 15, you can get the sum of the numbers less than 1000 that can be divisible by 3 or 5.
The following section describes how to calculate the sum of numbers divided by 3 or 5 in less than 1000 in JS. I hope this will help you!
Articles you may be interested in:
- Javascript code for Division
- Analysis of difference between the ceil and floor functions of JavaScript Division