#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// const int Amax = 10001; int A[Amax]; bool pdp[Amax]; vector> dp(Amax); vector ans(Amax); void makePrime(int N){ for(int i=2; i<= N; ++i){ if(pdp[i] == false){ for(int j = i+i; j<= N; j += i){ pdp[j] = true; dp[j].push_back(i); } }else{ for(int j = i+i; j<= N; j += i){ dp[j].push_back(i); } } dp[i].push_back(i); } return ; } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// int N; cin>>N; int Ymax=0; int ansCount = 1; cin>>ans[0]; int cintemp; for(int i=0;i>cintemp; Ymax = max(Ymax,cintemp+1); ++A[cintemp]; } makePrime(Ymax-1); int count = 1; int min = 1; while( A[1] ){//1を全部使う ans[ansCount] = 1; ++ansCount; --A[1]; } for(count = min; count::reverse_iterator yRItr = dp[ ter ].rbegin(); vector::reverse_iterator yRBegin = yRItr; vector::reverse_iterator yREnd = dp[ ter ].rend(); int temp; for(int i= 1; !ansFlag && yRItr != yREnd && i <= min ;++i){ while( yRItr != yREnd){ temp = i *ter/(*yRItr); if( temp < Ymax && A[temp] ){ ans[ansCount] = temp; --A[temp]; ++ansCount; ansFlag = true; break; } ++yRItr; } if(!ansFlag){ temp = i *ter;//約数1 if( temp < Ymax && A[temp] ){ ans[ansCount] = temp; --A[temp]; ++ansCount; ansFlag = true; break; } } yRItr = yRBegin; } if( !ansFlag ){ ans[ansCount] = min; --A[min]; ++ansCount; } } //////////// rep(i,N){ cout << ans[i]; if( i!=N-1){ cout << ' '; } }cout << '\n'; return 0; }