AtCoder Beginner Contest 162 - FizzBuzz Sum

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-----
15

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


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


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


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


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)


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


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


n = int(input())
print(sum([i for i in range(1, n + 1) if i % 3 and i % 5]))


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


N = int(input())
i = 1
a = 0
while i <= N:
	if i % 3 != 0 and i % 5 != 0:
		a += i
	i += 1
print(a)


print(sum([i * (i % 3 != 0) * (i % 5 != 0) for i in range(int(input()) + 1)]))


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


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


print(sum(filter(lambda x: not (x % 3 == 0 or x % 5 == 0), range(1, int(input()) + 1))))


print(sum((n for n in range(1, int(input()) + 1) if all([n % 3, n % 5]))))


n = int(input())
a = n // 3
b = n // 5
c = n // 15
print((n * (n + 1) - 3 * a * (a + 1) - 5 * b * (b + 1) + 15 * c * (c + 1)) // 2)


def sum(n):
	return n * (n + 1) // 2
N = int(input())
fizz_cnt = N // 3
buzz_cnt = N // 5
fizzbuzz_cnt = N // 15
print(sum(N) - sum(fizz_cnt) * 3 - sum(buzz_cnt) * 5 + sum(fizzbuzz_cnt) * 15)


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


s = int(input())
k = 0
for x in range(s + 1):
	if x % 3 != 0 and x % 5 != 0:
		k += x
print(k)


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


n = int(input())
l = []
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:
		l.append(i)
print(sum(l))


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


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)


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


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


a = 0
for i in range(1, int(input()) + 1):
	a += (not (i % 3 == 0 or i % 5 == 0)) * i
print(a)


n = int(input())
print(sum((x for x in range(1, n + 1) if x % 3 != 0 != x % 5)))


N = int(input())
out = 0
for items in range(N):
	if (items + 1) % 3 != 0 and (items + 1) % 5 != 0:
		out += items + 1
print(out)


n = int(input())
sum = 0
for i in range(1, n + 1):
	if i % 15 == 0:
		i = 'FizzBuzz'
	elif i % 3 == 0:
		i = 'Fizz'
	elif i % 5 == 0:
		i = 'Buzz'
	else:
		sum += i
print(sum)


def main() -> None:
	n = int(input())
	answer = 0
	for i in range(1, n + 1):
		if i % 3 != 0 and i % 5 != 0:
			answer += i
	print(answer)
	return

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	res = 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:
			res += i
	print(res)

def __starting_point():
	resolve()
__starting_point()


n = int(input())

def main(i):
	if i % 5 == 0 and i % 3 == 0:
		return 0
	elif i % 3 == 0:
		return 0
	elif i % 5 == 0:
		return 0
	else:
		return i
ans = 0
for i in range(n + 1):
	ans += main(i)
print(ans)


N = int(input())
print(sum([i for i in range(1, N + 1) if i % 3 if i % 5]))


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


n = int(input())
a = n // 3
a_1 = 3 * (a + 1) * a // 2
b = n // 5
b_1 = 5 * (b + 1) * b // 2
c = n // 15
c_1 = 15 * (c + 1) * c // 2
print(n * (n + 1) // 2 - a_1 - b_1 + c_1)


n = int(input()) + 1
(i, sum) = (1, 0)
while i < n:
	if i % 3 != 0 and i % 5 != 0:
		sum += i
	i += 1
print(sum)


n = int(input())
out = n * (n + 1) // 2
u = n // 5
out -= u * (u + 1) // 2 * 5
u = n // 3
out -= u * (u + 1) // 2 * 3
u = n // 15
out += u * (u + 1) // 2 * 15
print(out)


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


n = int(input())
a = [0] * (n + 1)
for i in range(n + 1):
	if i % 3 == 0 or i % 5 == 0:
		a[i] = 0
	else:
		a[i] = i
print(sum(a))


def to_fizzbuzz(number):
	if number % 15 == 0:
		return 'FizzBuzz'
	if number % 3 == 0:
		return 'Fizz'
	if number % 5 == 0:
		return 'Buzz'
	else:
		return str(number)

def main():
	N = int(input())
	fblist = []
	for number in range(1, 10 ** 6):
		result = to_fizzbuzz(number)
		fblist.append(result)
	n_list = fblist[0:N]
	n_numlist = []
	for s in n_list:
		if s.isdigit() == True:
			n_numlist.append(int(s))
	print(sum(n_numlist))
main()


c = 0
for i in range(int(input()) + 1):
	if (i % 3 != 0) & (i % 5 != 0):
		c += i
print(c)


print(sum((i ** 4 % 15 % 2 * i for i in range(int(input()) + 1))))


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n = int(input())
tmp = 0
res = 0
for i in range(1, n + 1):
	if i % 3 != 0 and i % 5 != 0:
		res += i
print(res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
N = ni()
ans = 0
for i in range(N + 1):
	if i % 3 != 0 and i % 5 != 0:
		ans += i
print(ans)


print(sum([k for k in range(int(input()) + 1) if k % 3 and k % 5]))


def N():
	return int(input())

def L():
	return list(map(int, input().split()))

def NL(n):
	return [list(map(int, input().split())) for i in range(n)]
mod = pow(10, 9) + 7
import sys
import math
import collections
n = N()
cnt = 0
for i in range(n + 1):
	if i % 3 != 0 and i % 5 != 0:
		cnt += i
print(cnt)


N = int(input())
L = list(range(1, N + 1))
M = list(filter(lambda n: n % 3 != 0 and n % 5 != 0, L))
print(sum(M))


def fizzBuzzSum(n: int) -> int:
	sum = 0
	for i in range(1, n + 1):
		if i % 3 != 0 and i % 5 != 0:
			sum += i
	return sum
n = int(input())
print(fizzBuzzSum(n))


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


N = int(input())
L_prime = [j for j in range(1, N + 1) if j % 3 != 0 and j % 5 != 0]
print(sum(L_prime))


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


from sys import stdin, stdout

def main():
	n = int(stdin.readline().rstrip())
	ans = 0
	for number in range(1, n + 1):
		if number % 3 != 0 and number % 5 != 0:
			ans = ans + number
	stdout.write(str(ans))
	stdout.write('\n')
main()


n = int(input())
li = [i for i in range(1, n + 1) if i % 3 != 0]
sum = 0
for i in li:
	if i % 5 != 0:
		sum += i
print(sum)


N = int(input())
cnt = 0
for i in range(N + 1):
	if i % 15 == 0:
		pass
	elif i % 3 == 0:
		pass
	elif i % 5 == 0:
		pass
	else:
		cnt += i
print(cnt)


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


n = int(input())
n3 = n // 3
n5 = n // 5
n15 = n // 15
print((n + 1) * n // 2 - 3 * (1 + n3) * n3 // 2 - 5 * (1 + n5) * n5 // 2 + 15 * (1 + n15) * n15 // 2)


N = int(input())
print(sum(map(lambda x: x if x % 3 != 0 and x % 5 != 0 else 0, list(range(N + 1)))))


N = int(input())
print(sum([x for x in range(1, N + 1) if x % 3 and x % 5]))


ans = 0
N = int(input())
c = 0
while c <= N:
	if c % 3 != 0 and c % 5 != 0:
		ans += c
	c += 1
print(ans)


N = int(input())
N_ = [i for i in range(N + 1)]
N3 = [3 * i for i in range(N // 3 + 1)]
N5 = [5 * i for i in range(N // 5 + 1)]
N15 = [15 * i for i in range(N // 15 + 1)]
print(sum(N_) - sum(N3) - sum(N5) + sum(N15))
return


n = int(input())
f = lambda x: n // x * (n // x + 1) * x // 2
print(f(1) - f(3) - f(5) + f(15))


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


n = int(input())
l3 = n // 3 * 3
l5 = n // 5 * 5
l15 = n // 15 * 15
print(n * (n + 1) // 2 - (3 + l3) * l3 // 6 - (5 + l5) * l5 // 10 + (15 + l15) * l15 // 30)


def readinput():
	n = int(input())
	return n

def main(n):
	ans = 0
	for i in range(1, n + 1):
		if i % 3 == 0 or i % 5 == 0:
			continue
		else:
			ans += i
	return ans

def __starting_point():
	n = readinput()
	ans = main(n)
	print(ans)
__starting_point()


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


N = int(input())
a = ''
sum = 0
for i in range(N + 1):
	if i % 3 == 0:
		a = 'Fizz'
	elif i % 5 == 0:
		a = 'Buzz'
	else:
		sum = sum + i
print(sum)


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


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


N = int(input())
temp = []
for i in range(1, N + 1):
	if i % 3 == 0 or i % 5 == 0 or (i % 3 == 0) & (i % 5 == 0):
		pass
	else:
		temp.append(i)
print(sum(temp))


l = list(range(int(input()) + 1))
ans = 0
for i in l:
	if i % 5 and i % 3:
		ans += i
print(ans)


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


N = int(input())
num = list(range(1, N + 1))
num1 = [i for i in num if i % 3 != 0 and i % 5 != 0]
print(sum(num1))