I am a beginner in programming on Python (my 1 programming language). He solved the problem No. 12 from the Euler project. I used a recursion in functions, but unfortunately, to solve the problem, I will have to use the recursion more than 1000 times. I would like to know how to solve this problem as before using a recursion in order to know about it in the future.
how to improve the code and what do you think about my names of variables and functions?
This is how the task is formed by the sequence of triangular numbers by adding natural numbers. For example, the 7th triangular number is 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten triangular numbers:
1, 6, 10, 15, 21, 28, 36, 45, 55, ...
We list the divisors of the first seven triangular numbers: 1: 1 3: 1, 3 6: 1, 2, 3, 6 10: 6 10: 6 10: 6 10: 6 10: 6 10: 6 10: 6 10: 6 10: 6 10: 6 10 10: 6 10: 6 10 10: 6 10 10: 6 10 10: 6 10 10: 6 10 10: 6 10: 6 10 10: 6 10 10: 6 10 10 1, 2, 5, 10 15: 1, 3, 5, 15 21: 1, 3, 7, 21 28: 1, 2, 4, 7, 14, 28 As we see, 28 is the first triangular number, which has more than five divisors.
What is the first triangular number that has more than five hundred divisors?
def tringle_number ( x ): if x == 1 : retu 1 else : Retu X + Tringle_number (x- 1 ) for i in range ( 1 , 900 ): a.Append (tringle_number (i)) print (a) need = 0 all_number = [ 1 ] count = 0 for item in a: number = 0 for j in range ( 1 , 100,000 ): it item % j == 0 : conside = J Number += 1 if number == : for items in all_number: need += 1 if need == 1 : all_number.append (item) else : continue else : Continue print (all_number [ 1 ]) r
question@mail.ru
·