using System; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; this.SetPrimeNumberList(); int numCount = int.Parse(Reader.ReadLine()); int[] intArr = Reader.GetInt(); List numList = new List(); foreach (int num in intArr) { numList.Add(new ItemNumber(num)); } List ansList = new List(); ansList.Add(numList[0]); numList.RemoveAt(0); ItemNumber target = ansList[0]; for(int i=1; i tmp || (minKoubai == tmp && numList[j].Value < minBaseNum)) { minIdx = j; minKoubai = tmp; minBaseNum = numList[j].Value; } } ansList.Add(numList[minIdx]); numList.RemoveAt(minIdx); target = ansList[ansList.Count - 1]; } StringBuilder ans = new StringBuilder(); foreach (ItemNumber item in ansList) { if(ans.Length > 0) { ans.Append(" "); } ans.Append(item.Value); } Console.WriteLine(ans.ToString()); } private void SetPrimeNumberList() { int maxNum = 10000; bool[] flag = new bool[maxNum + 1]; ItemNumber.PrimeNumberList = new List(); for(int i=2; i<=maxNum; i++) { if(!flag[i]) { ItemNumber.PrimeNumberList.Add(i); int maxIdx = maxNum / i; for(int j=1; j PrimeNumberList; public int Value = 0; public Dictionary Soinsu = new Dictionary(); public ItemNumber(int num) { this.Value = num; int tmp = num; while (tmp > 1) { for(int i=0; i tmp = new Dictionary(); Dictionary[] dicList = new Dictionary[] {this.Soinsu, target.Soinsu}; foreach (Dictionary dic in dicList) { foreach (int key in dic.Keys) { if(tmp.ContainsKey(key)) { tmp[key] = Math.Max(dic[key], tmp[key]); } else { tmp.Add(key, dic[key]); } } } int ans = 1; foreach (int key in tmp.Keys) { for(int i=1; i<= tmp[key]; i++) { ans *= key; } } return ans; } } public class Reader { private static String InitText = @" 5 1 2 3 4 5 "; private static System.IO.StringReader sr = null; public static bool IsDebug = true; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(InitText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i