Hi! There are a few basic mathematical ingredients in the mix.
Let's first try to solve the problem of computing the multiples of a single
number k up to a number n. If k is 1, then we want to sum all numbers between 1 and n.
This was solved by famous mathematician Gauss when he was around 10, by giving the Gauss sum n*(n+1)/2. What if k > 1? If m = n/k,
we can write: k + 2k + 3k + ... + mk as k(1+2+3...+m). So we use "m = n/k" instead of "n" in the Gauss sum (however, we have to take care of rounding, therefore the -1 in the solution) and first compute (1+2+...+m) = (m)(m+1)/2. We get the actual sum k+2k+... by multiplying the sum with k again.
The second tool used is the principle of inclusion / exclusion.
Are these pointers clarifying the code?
great
nice
that is awesome
Hi! There are a few basic mathematical ingredients in the mix.
Let's first try to solve the problem of computing the multiples of a single
number k up to a number n. If k is 1, then we want to sum all numbers between 1 and n.
This was solved by famous mathematician Gauss when he was around 10, by giving the Gauss sum n*(n+1)/2. What if k > 1? If m = n/k,
we can write: k + 2k + 3k + ... + mk as k(1+2+3...+m). So we use "m = n/k" instead of "n" in the Gauss sum (however, we have to take care of rounding, therefore the -1 in the solution) and first compute (1+2+...+m) = (m)(m+1)/2. We get the actual sum k+2k+... by multiplying the sum with k again.
The second tool used is the principle of inclusion / exclusion.
Are these pointers clarifying the code?
I am puzzled for this answer. can you give a link or something to explain this algorithm? thank you very much
why is it can compute the result?
what is the algorithm?
Thank you very much
great job