Sum of Consecutive Primes
InterviewTime limit0.7sMemory limit1024 MB
Given n up to 1,000,000, decide whether n is the sum of q consecutive primes for some prime q, across multiple test cases.
- Level
Medium4 of 10
- Topics
- Prefix sum, Math, Number theory
- Solved
- No attempts yet
Problem
A number is prime if and only if and has exactly two divisors, and . Two primes and are consecutive if and only if and there is no prime with .
Given , determine whether can be written as the sum of consecutive primes, where is prime.
Input
The input consists of several test cases. Each test case is a single line containing an integer .
The last line of the input is . Do not process this case.
Output
For each test case, print one line. Print "SIM" if can be written in the required form, or "NAO" otherwise.