0% found this document useful (0 votes)
30 views1 page

Greatest Common Divisor: GCD (A

The document describes a programming contest hosted in Vietnam that involves calculating the greatest common divisor (GCD) of integers in an array given a series of queries. Participants are given an array of integers, the number of queries, and each query asks to count pairs of indices whose GCD equals the query value. The input and output formats are described along with examples.

Uploaded by

Annowit Richard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Greatest Common Divisor: GCD (A

The document describes a programming contest hosted in Vietnam that involves calculating the greatest common divisor (GCD) of integers in an array given a series of queries. Participants are given an array of integers, the number of queries, and each query asks to count pairs of indices whose GCD equals the query value. The input and output formats are described along with examples.

Uploaded by

Annowit Richard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The 2019 ICPC Vietnam Central Provincial Programming Contest

Hosted by University of Science and Technology - The University of Danang

Greatest common divisor


• You are given an array a1, a2, ..., an consisting of n integers and q queries g1, ..., gq on it. For
each query gi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and
gcd(al, al + 1, ..., ar) = gi.
• With gcd(v1, v2, ..., vn)  is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest
positive integer that divides all vi.
You are given a string S that is guaranteed to be a beautiful binary string. Let N be the length of S.
Consider the lexicographically sorted list of all beautiful binary strings of length N. Compute and
return the string that comes immediately after S in this list. If S happens to be the last string in the
list, return an empty string instead.

Input
The first line of the input contains integer n, (1 ≤ n ≤ 105). The next line contains n space separated
integers a1, ..., an, (1 ≤ ai ≤ 109).
The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries.
Then follows q lines, each contain an integer gi, (1 ≤ gi ≤ 109).

Output
For each query print the result in a separate line.

Examples
Standard Input Standard Output
4 2
2463 4
5 2
1 1
2 1
3
4
6
6 10
10 20 3 15 60 16 0
6 3
1 1
2 0
3 2
4
5
15

You might also like