A31 - Divisors
提出
TLE
code: python
n = int(input())
three = 0
five = 0
threefive = 0
for i in range(1, n+1):
if i % 3 == 0:
three += 1
if i % 5 == 0:
five += 1
if i % 15 == 0:
threefive += 1
print(three + five - threefive)
解答
code: python
n = int(input())
a1 = (n // 3) # 3 で割り切れるものの個数
a2 = (n // 5) # 5 で割り切れるものの個数
a3 = (n // 15) # 3, 5 両方で割り切れるもの(= 15 の倍数)の個数
print(a1 + a2 - a3)