Project Euler #1: Multiples of 3 and 5

  • + 0 comments

    def sum_multiples(k, n): m = (n - 1) // k return k * m * (m + 1) // 2

    if name == 'main': t = int(input().strip())

    for _ in range(t):
        n = int(input().strip())  
        result = sum_multiples(3, n) + sum_multiples(5, n) - sum_multiples(15, n)
        print(result)