#C794. Wonderful Numbers Count

    ID: 51866 Type: Default 1000ms 256MiB

Wonderful Numbers Count

Wonderful Numbers Count

You are given an array of integers B and several queries. For each query, you are provided two indices Y and Z (1-indexed). Your task is to count how many numbers in the subarray B[Y...Z] are wonderful numbers.

A wonderful number is defined as a number whose sum of digits is strictly greater than its product of digits. In mathematical terms, for a number \( n \) with digits \( d_1, d_2, \ldots, d_k \), the number is wonderful if:

\( \sum_{i=1}^{k} d_i > \prod_{i=1}^{k} d_i \)

Process each query and output the count for each. The numbers in the array and the queries are given in a 1-indexed manner.

inputFormat

The input is read from standard input and has the following format:

T
M
B[1] B[2] ... B[M]
P
Y1 Z1
Y2 Z2
... 
YP ZP

Where:

  • T is the number of test cases.
  • For each test case:
    • M is the number of integers in the array.
    • The next line contains M space-separated integers forming the array B.
    • P is the number of queries.
    • Each of the next P lines contains two integers Y and Z, the starting and ending indices of a subarray.

outputFormat

For each query, output a single integer on a new line, representing the count of wonderful numbers in the specified subarray. All answers for all test cases are concatenated in the order they appear in the input.

## sample
1
5
13 24 36 45 56
3
1 3
2 4
1 5
1

0 1

</p>