Project Euler

Problem 5: Smallest multiple

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?. Run this solution at repl.io here.

      
        from prime_list import prime_list

        p = primelist(20)

        a = 1 #minimum product of primes that also create the numbers 1 to 20

        #multiple the primes together to get a lower bound
        for k in p:
          a = a*k

        #if 'a' is not divisble by every integer number less than 20
        #multiply 'a' by the necessary primes in 'p'
        for n in range(1,20):
          if a % n != 0:
            for j in p:
              if n % j == 0:
                a = a*j

        print(a)
      
    

back to code menu