You are viewing a single comment's thread. Return to all 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)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
def sum_multiples(k, n): m = (n - 1) // k return k * m * (m + 1) // 2
if name == 'main': t = int(input().strip())