Problem:
Score : 200 points

Problem Statement

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.

If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.

If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.

If none of the above holds, a_i=i.

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

Constraints

1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

Sample Input 1

15

Sample Output 1

60

The first 15 terms of the FizzBuzz sequence are:

1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}

Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.

Sample Input 2

1000000

Sample Output 2

266666333332

Watch out for overflow.

Solution in Python (3.8.2) (judge verdict: Accepted)

N = int(input())

SUM = N*(N+1)/2
# print(str(SUM))

Fizz_count = N//3
Buzz_count = N//5
FizzBuzz_count = N//15

## r>1
def GeometricProgression(a_1,r,n):
    return int(a_1*(r^n -1)/r-1)

def Touhi(a_1,d,n):
    return int(n*(2*a_1+(n-1)*d)/2)

# print(Touhi(1,1,5))

SUM_Fizz = Touhi(3,3,Fizz_count)
SUM_Buzz = Touhi(5,5,Buzz_count)
SUM_FizzBuzz = Touhi(15,15,FizzBuzz_count)

"""
print(str(SUM_Fizz))
print(str(SUM_Buzz))
print(str(SUM_FizzBuzz))
"""

result = int(SUM - SUM_Fizz - SUM_Buzz + SUM_FizzBuzz)
print(result)