Set 106Question 75

Arif's GCD-Optimal Subsequence Planner

ExtremeWritten in CMust finish in 5 seconds

Arif must precompute, for every possible team SIZE at a game studio, the maximum GCD achievable among rating sequences forming an increasing subsequence, all in one efficient pass.

What your program reads

Line1: N. Line2: N integers. Line3: Q. Next Q lines: K.

What your program prints

Max GCD for each K, or -1.

Limits

1 ≤ N,Q ≤ 10^5

Example input

5
4 8 6 12 3
2
2
4

Expected output

4
-1
main.c

Your work is saved in this browser as you type.

Loading editor…
Input for Run

Run tries your code on the input above and shows what it prints. Submit checks your output against every test, including hidden ones.

Shortcut: Ctrl + Enter sends it to the judge.

Arif's GCD-Optimal Subsequence Planner · DIU ContestHub