#C7171. Standardized Recipe Quantities

    ID: 51013 Type: Default 1000ms 256MiB

Standardized Recipe Quantities

Standardized Recipe Quantities

You are given a list of n ingredient quantities and q queries. For each query, you need to compute the greatest common divisor (GCD) of the first k ingredients, where k is specified in the query.

The GCD of two numbers a and b is mathematically defined as \(\gcd(a,b)\). For a list of numbers, the GCD is computed as \(\gcd(a_1,a_2,\ldots,a_k)\) = \(\gcd(\ldots\gcd(\gcd(a_1,a_2),a_3)\ldots,a_k)\).

Your task is to process each query and output the corresponding GCD.

inputFormat

The input is read from standard input (stdin) in the following format:

  1. An integer n representing the number of ingredients.
  2. A line of n space-separated integers representing the quantities of the ingredients.
  3. An integer q representing the number of queries.
  4. A line of q space-separated integers where each integer k specifies that you should consider the first k ingredients.

outputFormat

For each query, output the GCD of the first k ingredient quantities on a new line. The output should be written to standard output (stdout).

## sample
5
12 15 18 24 30
3
2 4 5
3

3 3

</p>