Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
The solution is based on python 2, which interprets "/" as integer division. You have to replace "/" by "//" for python 3.
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?
Maybe a tiny description of the spoken/shouted/... lambda function's semantics would be nice.