【每日一题1208】倍数之和

:mage:t2: 给定一个正整数n(可能会很大,例如超过100000),请求出0~n之间所有的3和5的倍数的总和。

示例:
输入:10,返回:23。
解释:10以内的3或5的倍数之和为:3+5+6+9=23。

题目难度:中等
题目来源:codewars: Multiples of 3 and 5 redux

def solution(n: int) -> int:
    # your code

assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    return sum(set([i for i in range(0, n, 3)] + [i for i in range(0, n, 5)]))


assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n:int) -> int:
    return sum ([i for i in range(n) if i%3==0 or i%5==0])


assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    return sum([num for num in range(n) if num%3 ==0 or num%5==0])

assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    # your code
    list_ = []
    for i in range(1, n):
        if i % 3 == 0 or i % 5 == 0:
            list_.append(i)
    return sum(list_)


assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    list1=[]
    for i in range(0,n):
        if i%3==0 or i%5==0:
            list1.append(i)
    return sum(list1)


assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    total = 0
    for i in range(n):
        total += i if i%3==0 or i%5==0 else 0
    return total
def solution(n: int) -> int:
    sum = 0
    for i in range(0 , n):
        if i % 3 == 0 or i % 5 == 0:
            sum += i
    return sum

assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668
def solution(n: int) -> int:
    sum = 0
    for i in range(n):
        if i % 3 == 0 or i % 5 == 0:
            sum += i
    return sum

assert solution(10) == 23
assert solution(20) == 78
assert solution(10000) == 23331668