[Baekjoon 1644] Sum of Consecutive Primes
Generate primes with a sieve, then search consecutive ranges whose sum matches the target.
July 18, 2022
First, I used the Sieve of Eratosthenes to mark primes up to the target. Then I chose each starting prime and added successive primes until the sum reached or exceeded the target.
Fix a starting prime.
Add the next prime.
If the sum equals N, increment the count.
If the sum exceeds N, move to the next start.
The prime list must be ready before checking consecutive sums. Once it is built, traversal can move only between primes without including composite numbers. I kept prime preprocessing and interval search as separate steps.
Problem: Baekjoon · Code: View on GitHub