728x90
λ¬Έμ
νμ΄
μλΌν μ€ν λ€μ€μ 체, λ ν¬μΈν°λ₯Ό μ¬μ©ν΄ νλ©΄ λλ€.
κ΅¬κ° ν©μ μ νμ¬ν..γ γ
λλλΉλμ κ°μμ μ λΆ μ 리λμ΄μλ€.
https://www.youtube.com/watch?v=cswJ1h-How0&list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC&index=9
μ½λ
import sys, math
input = sys.stdin.readline
n = int(input())
intervalSum = [0]
isPrimeList = [True for _ in range(n + 1)]
for i in range(2, int(math.sqrt(n)) + 1):
if isPrimeList[i]:
for j in range(i * 2, n + 1, i):
isPrimeList[j] = False
primeNumList = [i for i in range(2, n + 1) if isPrimeList[i]]
tempSum = 0
for prime in primeNumList:
tempSum += prime
intervalSum.append(tempSum)
cnt = 0
start = end = 1
while start < len(intervalSum) and end < len(intervalSum):
if intervalSum[end] - intervalSum[start - 1] == n:
cnt += 1
start += 1
elif intervalSum[end] - intervalSum[start - 1] < n:
end += 1
else:
start += 1
print(cnt)
λ§λ¬΄λ¦¬
μλΌν μ€ν λ€μ€μ 체, κ΅¬κ° ν© λ± μ€λλ§μ μ¨λ³Έ μκ³ λ¦¬μ¦μ΄ λ§μλ€.
728x90