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];
}
}

posted @ 2024-03-12 22:16  _Yxc  阅读(44)  评论(0)    收藏  举报