#P17846. 回天
回天
Problem Description
Through one "Kaiten" (turning back fate) after another, Homura Akemi keeps rewriting the causality of the world.
She holds a sequence of length . At each moment, Homura Akemi changes the value at some position; then Madoka Kaname observes the current sequence after the change and computes the chaos value of this sequence.
For a sequence, partition all of its elements into two non-empty multisets . Define the value of a multiset as the greatest common divisor of all its elements, that is, .
The chaos value of the sequence is defined as the maximum of over all ways of partitioning.
Please help Madoka Kaname compute the chaos value of the current sequence after each of Homura Akemi's changes.
Input Format
The first line contains one integer (), denoting the length of the sequence in Homura Akemi's hands.
The second line contains integers (), denoting the initial state of the sequence.
The third line contains one integer (), denoting the number of changes.
The next lines each contain two integers () and (), meaning that the value of is changed to .
Output Format
Output lines.
The first line outputs the chaos value of the sequence before any change.
For the -th change, the -th line outputs the chaos value of the sequence after that change is completed.
4
2 2 3 3
2
3 2
4 4
5
5
6
Hint
The sequence after each change in the sample and one optimal partition are as follows:
| Current sequence | Optimal partition |
|---|---|
| , chaos value | |
| , chaos value | |
| , chaos value |
Translated by QwenWork