Swapping Bibs (AOJ 0620) by ynu_c
Contest: 3421    RunID: 2277216    Status: Wrong Answer    Date: Sun Apr 23 16:51:50 JST 2017


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a[n];
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int k=2;k<m+1;k++){
        for(int i=0;i<n-2;i++){
            if(a[i]%k>a[i+1]%k){
               swap(a[i],a[1+i]);
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}