#C10010. Subarray Prime Queries

    ID: 39169 Type: Default 1000ms 256MiB

Subarray Prime Queries

Subarray Prime Queries

You are given an array of n integers and m queries. For each query, you are given two indices l and r (1-indexed). Your task is to determine whether the sum of the subarray from index l to r is a prime number.

Recall that a number is prime if it is greater than 1 and has no positive divisors other than 1 and itself. The condition can be represented in \(\LaTeX\) as follows:

( n > 1 \quad\text{and}\quad \forall d \in \mathbb{Z},; 1 < d < n,; d \nmid n )

For each query, output YES if the sum is prime, and NO otherwise.

inputFormat

The first line contains two integers n and m, where:

  • n is the number of elements in the array.
  • m is the number of queries.

The second line contains n space-separated integers representing the array elements.

Each of the next m lines contains two integers l and r (1-indexed) indicating the start and end indices of a query.

outputFormat

For each query, output a line with either YES if the sum of the subarray is a prime number, or NO otherwise.

## sample
6 3
3 4 6 2 7 5
1 3
2 5
1 6
YES

YES NO

</p>