D. Divide by three, multiply by two
https://codeforces.com/contest/977/problem/D
void solve(){
int n;
cin >> n;
vector<pair<int, long long>> a(n);
for (auto&[x, y] : a){
cin >> y;
x = 0;
long long temp = y;
while (temp % 3 == 0){
x --;
temp /= 3;
}
}
sort(a.begin(), a.end(), [&](const pair<int, long long>& i, const pair<int ,long long>& j){
return i.first != j.first ? i.first < j.first : i.second < j.second;
});
for (int i = 0; i < n; ++i){
cout << a[i].second << " \n"[i == n - 1];
}
}

浙公网安备 33010602011771号