No.1730 GCD on Blackboard in yukicoder
Problem Statement
Solve the following problem for each $K=0,1,\ldots,N-1$.Original problem: ABC125-C (GCD on Blackboard)$N$ integers $A_1, A_2, \ldots, A_N$ are written on a blackboard.
You choose exactly $K$ of these integers and rewrite each of them to any integer of your choice between $1$ and $10^6$, inclusive.
You may rewrite an integer to the same integer as the original one.
Find the maximum possible greatest common divisor of the $N$ integers after rewriting.
Input
$N$ $A_1\ A_2\ \ldots\ A_N$
- $2\leq N\leq 2\times 10^5$
- $1\leq A_i\leq 10^6$
- All inputs are integers.
Output
Output $N$ lines. On the $i$-th line, output the answer for $K=i-1$.
Sample
Sample 1
Input
3 8 6 12
Output
2 6 12
- When $K=0$, nothing is rewritten. $\gcd(8,6,12)=2$.
- When $K=1$, for example, rewriting $8$ to $12$ gives $\gcd(12,6,12)=6$, which is the maximum.
- When $K=2$, for example, rewriting $8$ to $36$ and $6$ to $24$ gives $\gcd(36,24,12)=12$, which is the maximum.
Sample 2
Input
2 1000000 1000000
Output
1000000 1000000
It is also possible to rewrite an integer to the same integer as the original one.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
とりゐ
るさ