I have just started learning python and I am solving Project Euler problems alongside for practice. This is my solution for problem 5. Project Euler asks for the minimum value divisible by all numbers from 1 to 20 but I have made the program so it works from 1 to n.
I think there is a lot of room for improvement in it and I need your suggestions. Please tell me how I can improve it.
def least(x): """ Variables: x = Argument of function and the maximum value of range. n = Number that is going to be tested by loops in each cycle. a = Number that is going to be added to "n" in each cycle of loop. It is initialized with "x". For example: if we check for all numbers from 1 to 10, each "n" has to be multiple of 10. So that's why a will be added to n in each turn. y = To minimize machine time, I have tried to bring argument of "least" function below 10. So if x is bigger than 10, y will be x - 10. And then we will do recursion and use "least" on y. For example: If we check from 1 to 40. least(40) -> n = least(30) = a (calls least(30) to get n and a) least(30) -> n = least(20) = a (calls least(20) to get n and a) least(20) -> n = least(10) = a (calls least(10) to get n and a) least(10) -> n = 10, a =10, (Brute Check) (Brute Check) (At each stage "for loop" checks "n" in each loop cycle and adds "a" until value found.) """ if x <= 10: n = x #The first number to test a = x #a is number that's going to be added in each turn else: y = x - 10 n = least(y) #Recursion to minimize machine load and time a = n while True: d = 0 for i in range(1,x + 1): if n % i == 0: d += 1 #counts if i evenly divides. else: break #Checks each n. If i doesn't evenly divide, skips loop cycle. if d == x: #if each "i" divides evenly, d will be equal to x and thus minimum value will be n. return n else: n += a #adds a(specified above) minimumvalue = least(int(input("Minimum Value divisible by all integers from 1 to n.\n Specify n: "))) print(" Minimum Value: " + str(minimumvalue))