Showing posts with label problem 12. Show all posts
Showing posts with label problem 12. Show all posts

2017-06-14

Project Euler Problem 12

Finding divisors of summed natural numbers. This time I'm creating a function for doing the divisor checking. Just as in atleast one previous problem, this is a problem which can be solved with a mathematical sieve. Since my math skills obviously aren't good enough I took help from google and found a way to, by using the square root of the number to be checked, calculate the number of divisors of a triangle number. As so often in math, when you have the solution it's all so obvious.






 My math skills and patience weren't as good as they should have been for this problem. Programatically it worked out though!



number = 0

def number_of_divisors(val):
    divisors = 0    for y in range(1, int(val ** 0.5)):
        if val % y == 0:
            divisors += 2
    return divisors


for x in range(0, 10 ** 10):
    if number_of_divisors(number) > 500:
        print(number)
        break    number += x


 /Ludvig