hugDog
Android DevLog
hugDog
전체 방문자
였늘
μ–΄μ œ
  • πŸ™Œ Hello? (162)
    • πŸ§©μ•ˆλ“œλ‘œμ΄λ“œ (12)
      • κ°œλ… 정리 (5)
      • 버그 ν•΄κ²° (4)
      • 기타 (3)
    • πŸ”μ•Œκ³ λ¦¬μ¦˜ (54)
      • κ°œλ… (0)
      • λ°±μ€€ (48)
      • ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ (6)
    • πŸ“„κ°œλ°œ 일지 (0)
      • FINPO (0)
    • πŸ”€ν”„λ‘œκ·Έλž˜λ° μ–Έμ–΄ (71)
      • C++ 정리 (49)
      • C++κΈ°μ΄ˆν”ŒλŸ¬μŠ€ μ—°μŠ΅λ¬Έμ œ (20)
      • Kotlin (2)
    • ⭐Project (1)
    • 🚴TIL (13)
      • Clean Code (13)
    • πŸš©κΈ°νƒ€ (9)
      • λͺ©ν‘œ (6)
      • 일상 (3)
      • λ¬Έμ„œ (0)

인기 κΈ€

졜근 λŒ“κΈ€

졜근 κΈ€

ν‹°μŠ€ν† λ¦¬

hELLO Β· Designed By μ •μƒμš°.
hugDog

Android DevLog

[Python/파이썬] λ°±μ€€ 1644번: μ†Œμˆ˜μ˜ 연속합
πŸ”μ•Œκ³ λ¦¬μ¦˜/λ°±μ€€

[Python/파이썬] λ°±μ€€ 1644번: μ†Œμˆ˜μ˜ 연속합

2022. 2. 17. 15:45
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
μ €μž‘μžν‘œμ‹œ λΉ„μ˜λ¦¬ (μƒˆμ°½μ—΄λ¦Ό)
    'πŸ”μ•Œκ³ λ¦¬μ¦˜/λ°±μ€€' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€
    • [Python/파이썬] λ°±μ€€ 15989번: 1, 2, 3 λ”ν•˜κΈ° 4
    • [Python/파이썬] λ°±μ€€ 1781번: 컡라면
    • [Python/파이썬] λ°±μ€€ 1202번: 보석 도둑
    • [Python/파이썬] λ°±μ€€ 1208번: λΆ€λΆ„μˆ˜μ—΄μ˜ ν•© 2
    hugDog
    hugDog
    μ•ˆλ“œλ‘œμ΄λ“œ 곡뢀 쀑인 ν•™μƒμž…λ‹ˆλ‹€!

    ν‹°μŠ€ν† λ¦¬νˆ΄λ°”