Project Euler #1: Multiples of 3 and 5

  • + 0 comments
    import sys
    t = int(input().strip())
    for a0 in range(t):
        n = int(input().strip())
        three=(n-1)//3
        five=(n-1)//5
        fifteen=(n-1)//15
        print((3*(three*(three+1)//2)+5*(five*(five+1)//2)-15*(fifteen*(fifteen+1)//2)))