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.



Sample input:
15


Sample output:
60

Submission status: Accepted

Solution code:
N = int(input()) + 1
sum = 0
for i in range(1,N):
    if not i % 3 == 0 and not i % 5 == 0:
        sum += i
print(sum)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for num in range(1, n+1):
    if num % 3 == 0:
        continue
    if num % 5 == 0:
        continue
    ans += num

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
total = 0
for i in range(1, n+1):
  if i % 3 != 0 and i % 5 != 0:
    total += i
print(total)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
for i in range(1,N+1):
    if i%3==0 or i%5==0:
        continue
    ans+=i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for i in range(1,n+1) :
  if i%15 == 0 :
    continue
  if i%3 == 0 :
    continue
  if i%5 == 0 :
    continue
  ans += i
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


sum = 0
for n in range(1, N+1):
    if not((n % 3 == 0) or (n % 5 == 0)):
        sum += n

print(sum)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

for i in range(1,n+1):
    if i%3!=0 and i%5!=0:
        ans += i

print(ans)

Submission status: Accepted

Solution code:
x = int(input())
total = 0
for i in range(1, x+1):
    if i % 3 == 0 or i % 5 == 0:
        pass
    else:
        total += i
print(total)

Submission status: Accepted

Solution code:
n=int(input())
s=0
for i in range(1,n+1):
    if i%3!=0 and i%5!=0:
        s=s+i
print(s)

Submission status: Accepted

Solution code:
N = int(input())

# fizzbuzz = [1, 3, 3, 7, 7, 7, 14, 22, 22, 22, 33, 33, 46, 60]

ans = 0

for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        # print(i)
        ans += i
    # print(i)

print(ans)

Submission status: Accepted

Solution code:
def nsum(n):
	return (n * (n + 1)) // 2

def contains(s):
	ans = nsum(s) - nsum(s // 3) * 3 - nsum(s // 5) * 5 + nsum(n // 15) * 15
	return ans


n = int(input())
print(contains(n))

Submission status: Accepted

Solution code:
# B - FizzBuzz Sum
def main():
    N = int(input())
    is_fizzbuzz = [False] * (N + 1)
    is_fizzbuzz[::3] = [True] * (N // 3 + 1)
    is_fizzbuzz[::5] = [True] * (N // 5 + 1)
    ans = sum(i for i, b in enumerate(is_fizzbuzz) if not b)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, n + 1):
    if i % 5 == 0 or i % 3 == 0:
        continue
    else:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
k = 0
def fizz(n,k):
    for ele in range(n+1):
        if ele%15==0:
            continue
        elif ele%3 == 0:
            continue
        elif ele%5 == 0:
            continue
        else:
            k += ele
    return k
n = int(input())
print(fizz(n,0))

Submission status: Accepted

Solution code:
a=0
for i in range(int(input())+1):
    if i%3!=0 and i%5!=0:
        a+=i
print(a)

Submission status: Accepted

Solution code:
sum = 0
n=input()
for i in range(int(n)+1):
  if i % 3 != 0 and i % 5 != 0:
    sum += i
print(sum)

Submission status: Accepted

Solution code:
print(sum(i for i in range(int(input())+1) if i %3 !=0 and i%5!=0))

Submission status: Accepted

Solution code:
n=int(input())
summ=0
for i in range(1,n+1):
    if(i%3!=0 and i%5!=0):
        summ+=i
        
print(summ)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = 0
for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
x = int(input())

ans = 0
for i in range(x+1):
  ans += i if i%3 and i%5 else 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
total = 0
for i in range(N + 1):
    if i == 0:
        continue
    else:
        if i % 3 == 0:
            continue
        else:
            if i % 5 == 0:
                continue
            else:
                total = total + i

print(total)

Submission status: Accepted

Solution code:
N = int(input())
s = 0
for i in range(1, N + 1):
    if i % 3 and i % 5: s += i
print(s)

Submission status: Accepted

Solution code:
print(sum(i%3>0<i%5and i for i in range(int(input())+1)))

Submission status: Accepted

Solution code:
n=int(input())
sum = 0
for i in range(1,n+1):
    if i%3==0 and i%5==0:
        pass 
    elif i%3==0:
        pass 
    elif i%5==0:
        pass 
    else:
        sum+=i 
print(sum)

Submission status: Accepted

Solution code:
N = int(input())

result = 0
for i in range(N):
    if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:
        result += i + 1

print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans.append(i)
    print(sum(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
sum = 0
for i in range(1, n+1):
    if i%3!=0 and i%5!=0:
        sum += i

print(sum)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())

def main():
    ans = sum([x for x in range(1, n + 1) if x % 3 and x % 5])
    print(ans)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
print(sum(filter(lambda x:(x%3!=0 and x%5!=0),range(1,int(input())+1))))

Submission status: Accepted

Solution code:
N = int(input())
sumval = 0
for i in range(N + 1):
    if i % 3 != 0 and i % 5 != 0:
        sumval += i
print(sumval)

Submission status: Accepted

Solution code:
from functools import lru_cache

N = int(input())
 
@lru_cache(maxsize=1000)
def main(K):
    ans = 0
    for i in range(1, N+1):
        if i % 15 != 0 and i % 3 != 0 and i % 5 != 0:
            ans = ans + i
    return(ans)
 
print(main(N))

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for n in range(1,N+1):
    if n%3 != 0 and n%5 != 0:
        ans += n
print(ans)

Submission status: Accepted

Solution code:
print(sum([i for i in range(int(input())+1) if i%3!=0 and i%5!=0]))

Submission status: Accepted

Solution code:
def f(n):
    if n % 3 == 0 or n % 5 == 0:
        return 0
    return n


N = int(input())
ans = 0
for n in range(1, 1 + N):
    ans += f(n)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = 0
for i in range(N+1):
    if i%3>0 and i%5>0:
        s+=i
print(s)

Submission status: Accepted

Solution code:
n = int(input())


def sum(a, b):
    return int((a+1)*a/2*b)


fizz_num = n//3
buzz_num = n//5
fizzbuzz_num = n//15


print(sum(n, 1)-sum(fizz_num, 3)-sum(buzz_num, 5)+sum(fizzbuzz_num, 15))

Submission status: Accepted

Solution code:
a = 0
N = input()
n = int(N)
for i in range(1,n+1):
    if i % 5 != 0 and i % 3 != 0:
        a = a + i
    else:
        continue
print(a)

Submission status: Accepted

Solution code:
N = int(input())  #スペース抜きの複数行,１文字ずつ
 
A = []
for i in range(1,N+1):
  if i % 3 == 0:
    A.append(0)
  elif i % 5 == 0:
    A.append(0)
  else:
    A.append(i)

print(sum(A))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    ans = 0
    for i in range(1, N + 1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            ans += i
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

print(sum(i for i in range(1, N+1) if i % 5 != 0 and i % 3 != 0))

Submission status: Accepted

Solution code:
n = int(input())
sums = 0
for i in range(1,n+1):
    if i % 3 == 0 or i % 5 == 0:
        pass
    else:
        sums += i
print(sums)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, n + 1):
    if i % 15 == 0:
        continue
    elif i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    else:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
import numpy as np
d = np.array(range(1,n+1))
print(np.sum(d) - np.sum(d[d%3==0]) - np.sum(d[d%5==0]) + np.sum(d[d%15==0]))

Submission status: Accepted

Solution code:
N = int(input())
Q = 0
for i in range(1,N+1):
  if(i%3 != 0 and i%5 != 0):
      Q += i
print(Q)

Submission status: Accepted

Solution code:
n = int(input())
sum_ = 0
for i in range(1, n + 1):
  if i % 3 != 0 and i % 5 != 0:
    sum_ += i
print(sum_)

Submission status: Accepted

Solution code:
n = int(input())
k = n//3
l = n//5
m = n//15
print(int(n*(n+1)/2-5*l*(l+1)/2-3*k*(k+1)/2+15*m*(m+1)/2))

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1, N+1):
    if i%3!=0 and i%5!=0:
        ans+=i

print(ans)

Submission status: Accepted

Solution code:
n=int(input())+1
c=0
for i in range(1,n):
    if i%3!=0 and i%5!=0:
        c+=i
print(c)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1, N+1):
  if i%3 and i%5:
    ans += i

print(ans)

Submission status: Accepted

Solution code:
a=int(input())
rs=0
for i in range(1,a+1):
    
   
    if i%3==0:
        
        continue
    if i%5==0:
        
        continue
    rs=rs+i
print(rs)

Submission status: Accepted

Solution code:
from math import *

N= int(input())

ans = 0
for i in range(N+1):
    if i%3 != 0 and i%5 !=0:
        ans += i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def find_sum(n):
    res = 0
    for i in range(1, n+1):
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            res += i
    return res
print(find_sum(n))

Submission status: Accepted

Solution code:
n=int(input())
su=0
for i in range(1,n+1):
    if i%3==0 and i%5==0:
        continue
    elif i%3==0:
        continue
    elif i%5==0:
        continue
    else:
        su+=i
print(su)

Submission status: Accepted

Solution code:
N = int(input())
num = []
num2= []
for i in range(N+1):
  if i % 3 == 0 and i % 5 == 0:
    num.append(i)
  if i % 5 == 0:
    num.append(i)
  elif i % 3 == 0:
    num.append(i)
  else:
    num2.append(i)

print(sum(num2))

Submission status: Accepted

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())

cnt = 0
for i in range(1, N+1):
    if i%3==0 or i%5==0:
        pass
    else:
        cnt += i
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = 0
for  i  in range(1,n+1):
  if i % 3 != 0 and i % 5 != 0:
    s += i
print(s)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, n+1):
    if i%3 == 0 or i%5 == 0:
        pass
    else:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1,N+1):
    if i%3 != 0 and i%5 != 0:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
res = 0
for i in range(1, n+1):
    if i % 3 == 0 or i % 5 == 0:
        continue
    res += i
print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = 0

for i in range(n + 1):
  
  if i % 3 == 0 and i % 5 == 0:
    continue
  elif i % 3 == 0:
    continue
    
  elif i % 5 == 0:
    continue
    
  else:
    s = s + i
    
print(s)

Submission status: Accepted

Solution code:
n=input()
 
sum=0
 
for i in range(1,int(n)+1):
  if (i%3!=0)&(i%5!=0):
    sum+=i
    
print(sum)

Submission status: Accepted

Solution code:
def wa(n):
    return int(n*(n+1)/2)

n=int(input())
fizz=int(n/3)
butt=int(n/5)
fizzbutt=int(n/15)
fizz_wa=wa(fizz)*3
butt_wa=wa(butt)*5
fizzbutt_wa=wa(fizzbutt)*15
total=wa(n)
answer=total+fizzbutt_wa-fizz_wa-butt_wa
print(answer)

Submission status: Accepted

Solution code:
s=0
for i in range(1,int(input())+1):
  if i%15!=0 and i%3!=0 and i%5!=0:
    s+=i
print(s)

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    ans = sum(x for x in range(1, N + 1) if (x % 3 != 0) and (x % 5 != 0))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()

	ans = 0
	for i in range(1,N+1):
		if i % 3 == 0 or i % 5 == 0:
			ans += 0
		else:
			ans+= i

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))

# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
a = int(input())
b = []

for i in range(a+1):
    if i % 3 == 0 and i % 5 == 0:
      pass
    elif i % 3 == 0:
      pass
    elif i % 5 == 0:
      pass
    else:
      b.append(i)
print(sum(b))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(n+1):
    if i % 3 == 0 or i%5 == 0:
        ans += 0
    else:
        ans+=i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N+1):
  if i%3 != 0 and i%5 != 0:
    ans += i

print(ans)

Submission status: Accepted

Solution code:
print(sum([x for x in range(1,int(input())+1) if (x%3!=0)and(x%5!=0)]))

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(N+1):
    if i%3!=0 and i%5!=0 :
        ans += i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
res = 0
for i in range(1, n+1):
    if i % 3 == 0 or i % 5 == 0:
        continue
    res += i
print(res)

Submission status: Accepted

Solution code:
N = int(input())

sum_all = (N * (N + 1)) // 2
sum_three = 3 * ((N // 3) * (N // 3 + 1)) // 2
sum_five = 5 * ((N // 5) * (N // 5 + 1)) // 2
sum_fifteen = 15 * ((N // 15) * (N // 15 + 1)) // 2

ans = sum_all - sum_three - sum_five + sum_fifteen

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def f(num):
  return num*(num+1)/2

n1 = int(n/3)
n2 = int(n/5)
n3 = int(n/15)

sm = f(n)- 3*f(n1)-5*f(n2) + 15*f(n3)
# f(n)- 3*f(int(n/3))

print(int(sm))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, n+1):
    if 0 != i%3 and 0 != i%5:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = 0
for i in range(N+1):
  if i%3 != 0 and i%5 != 0:
    S += i
print(S)

Submission status: Accepted

Solution code:
print(sum(i*(i%5>0<i%3)for i in range(int(input())+1)))

Submission status: Accepted

Solution code:
n = int(input())

total = {}
for i in (1, 3, 5, 15):
    total[i] = i * (n // i) * (n // i + 1) // 2

print(total[1] - total[3] - total[5] + total[15])

Submission status: Accepted

Solution code:
print(sum(i*(min(i%5,i%3)!=0)for i in range(int(input())+1)))

Submission status: Accepted

Solution code:
n = int(input())
total = 0
for i in range(1,n+1):
    if i%3 != 0 and i%5 !=0:        
        total += i
    
print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
N=int(input())
A=set(range(1,N+1))
A=A-set(range(1,N+1)[2::3])-set(range(1,N+1)[4::5])
print(sum(A))