yukicoder-14

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

{{{
#!html
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="http://10.71.10.90/sfiction/tool/MathJax/MathJax-master/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
.input, pre {
    display: block;
    padding: 9.5px;
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.42857143;
    color: #333;
    word-break: break-all;
    word-wrap: break-word;
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
}
</style>
}}}

== [https://yukicoder.me/problems/no/14 No.14 最小公倍数ソート] ==

=== Description ===

{{{
#!html
<p>给出$N$个正整数$a_1,a_2,\dots,a_n$。考虑执行如下过程$N$次:第$i$次固定$a_i$不动,把其他数按照和$a_i$的最小公倍数大小排序。求最后每个位置的数。</p>
}}}

=== Input ===

{{{
#!html
<p class="input">
$N$<br>
$a_1$ $a_2$ $\dots$ $a_N$<br>
</p>

<p>$1 \le N, a_i \le 10000$。</p>
}}}

=== Output ===

{{{
#!html
<p>输出$N$个数。</p>
}}}

=== Sample ===

==== Sample 1 ====
输入
{{{
#!html
<pre>
5
1 2 3 4 5
</pre>
}}}
输出
{{{
#!html
<pre>
1 2 4 3 5
</pre>
}}}

==== Sample 2 ====
输入
{{{
#!html
<pre>
5
4 8 1 2 4
</pre>
}}}
输出
{{{
#!html
<pre>
4 1 2 4 8
</pre>
}}}

==== Sample 3 ====
输入
{{{
#!html
<pre>
10
9 9 3 7 5 9 1 5 2 1
</pre>
}}}
输出
{{{
#!html
<pre>
9 1 1 2 3 9 9 5 5 7
</pre>
}}}

No.14 最小公倍数ソート

Description

给出$N$个正整数$a_1,a_2,\dots,a_n$。考虑执行如下过程$N$次:第$i$次固定$a_i$不动,把其他数按照和$a_i$的最小公倍数大小排序。求最后每个位置的数。

Input

$N$
$a_1$ $a_2$ $\dots$ $a_N$

$1 \le N, a_i \le 10000$。

Output

输出$N$个数。

Sample

Sample 1

输入

51 2 3 4 5

输出

1 2 4 3 5
Sample 2

输入

54 8 1 2 4

输出

4 1 2 4 8
Sample 3

输入

109 9 3 7 5 9 1 5 2 1

输出

9 1 1 2 3 9 9 5 5 7