What does the script in Python?

I performed the task of Project Euler, in which you want to find the smallest number that is evenly divisible by the numbers from 1 to 20 inclusive. I realized that you can use a loop with range, but never figured out how, decided otherwise.
Later in the review found such script, but have not figured out how it works. Please explain.

As i increases, if the second condition(in the inner loop) does not work? First executes the outer loop or the inner?
i = 1
for k in (range(1, 21)):
 if i % k > 0:
 for j in range(1, 21):
 if (i*j) % k == 0:
 i *= j
break
print (i)
March 19th 20 at 08:29
3 answers
March 19th 20 at 08:31
Solution
First flash the first cycle to the condition when it is running - when the second cycle to the condition as soon as it runs - i changes and goes to the first cycle. i didn't change until the script does not proceed to the second cycle, the second cycle it moves only when the condition in the first.
For such things are sometimes useful to use print at each iteration of each cycle, to see where what happens if it is difficult to understand it immediately.
March 19th 20 at 08:33
I realized that you can use a loop with range, but never figured out how, decided otherwise.

The number, which evenly divided by some other number called the Least Common Multiple (LCM). This is taught in school, but not all. To calculate the NOC is the formula that expresses it through the GCD (Greatest Common Divisor) - this is taught in school, but not all.
So how is it at school?
from math import gcd

a = 2
for b in range(3, 21):
 a = a * b // gcd(a, b)
print(a)
Not necessarily rude)) I'm not familiar with the math library, just started to learn Python. Thanks for the interesting solution. - Aliya_Runolfsson commented on March 19th 20 at 08:36
@Aliya_Runolfsson, gcd, aka GCD, it can be calculated without using the library - old Euclid came up with this algorithm.
And here another:
On the interval [1, 20] there are eight Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19.
The maximum power of two in the interval [1, 20] - 2^4, three - 3^2, five and more - 5^1 and on.
print(16 * 9 * 5 * 7 * 11 * 13 * 17 * 19) - arnoldo_Ferry89 commented on March 19th 20 at 08:39
Very interesting, didn't know it. Can you recommend a math book, where can I read more? (preferably without the "algebra grade 11", in my book this was not) - Aliya_Runolfsson commented on March 19th 20 at 08:42
@Aliya_Runolfsson, I don't know such book.
This fact (about the power of a Prime) as something obvious - it's simple, from where they are to knock to take more than the maximum, but to a lesser does not.
Simply because of all the possible solutions you brought here is not the worst but pretty dumb, and the answer, marked with the solution here, the code does not explain.
You can do without the jokes, but when the issue shows that the author does not understand neither in Python nor in mathematics, it is causing some irritation - where to start the explanation? - arnoldo_Ferry89 commented on March 19th 20 at 08:45
March 19th 20 at 08:35
Two
6
12
60
420
840
2520
27720
360360
720720
12252240
232792560
i j k
2 2 2
6 3 3
12 2 4
60 5 5
420 7 7
840 2 8
2520 9 3
27720 11 11
360360 13 13
720720 2 16
12252240 17 17
232792560 19 19 - quentin.Mueller81 commented on March 19th 20 at 08:38

Find more questions by tags Python