[Python] What is the fastest way to solve Project Euler #5?

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I already have a way to solve Project Euler #5 (https://projecteuler.net/problem=5), but it takes forever to solve it! I've tried eliminating numbers from 1 - 10, and I'm skip-counting by 20, but still it doesn't solve fast enough. Here's my code -

    import time
    start_time = time.time()

    for i in range(1,100000000000000000):
    if i % 11 == 0 and\
    i % 12 == 0 and\
    i % 13 == 0 and\
    i % 14 == 0 and\
    i % 15 == 0 and\
    i % 16 == 0 and\
    i % 17 == 0 and\
    i % 18 == 0 and\
    i % 19 == 0 and\
    i % 20 == 0:
    print(i + 19)
    break

    print(time.time() - start_time," seconds taken to run program")

    Continue reading...

Compartilhe esta Página