Under construction

Still being built. Things may change

Sum of Consecutive Primes

Interview

Time limit0.7sMemory limit1024 MB

Summary
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 kk is prime if and only if k≥2k \ge 2 and kk has exactly two divisors, 11 and kk. Two primes kk and ll are consecutive if and only if k<lk < l and there is no prime pp with k<p<lk < p < l.

Given nn, determine whether nn can be written as the sum of qq consecutive primes, where qq is prime.

Input

The input consists of several test cases. Each test case is a single line containing an integer 2≤n≤10000002 \le n \le 1000000.

The last line of the input is n=0n = 0. Do not process this case.

Output

For each test case, print one line. Print "SIM" if nn can be written in the required form, or "NAO" otherwise.

Examples1

  1. Example 1

    Input
    5
    6
    7
    8
    9
    10
    0
    
    Expected output
    SIM
    NAO
    NAO
    SIM
    NAO
    SIM