Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Zailagend1
Problemset: C.Sort Number
Language: cpp
Time: 0.056 second
Submitted On: 2026-09-19 22:56:02
#include<bits/stdc++.h>
using namespace std;
int main(){
// Optimize input/output operations to prevent TLE timeouts
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a;
if (!(cin >> a)) return 0;
vector<pair<int,string>> b(a);
for(int i = 0; i < a; i++){
cin >> b[i].first >> b[i].second;
}
unordered_map<char,int> decoder = {
{'0',0}, {'1',1}, {'2',2}, {'3',3}, {'4',4},
{'5',5}, {'6',6}, {'7',7}, {'8',8}, {'9',9},
{'A',10}, {'B',11}, {'C',12}, {'D',13}, {'E',14}, {'F',15}
};
// set handles long long inputs perfectly
set<long long> result;
for(pair<int,string> x : b){
long long exp = 1;
long long res = 0;
string s = x.second;
reverse(s.begin(), s.end());
for(char y : s){
res += exp * decoder[y];
// Prevent overflow inside the multiplier loop
if (exp > LLONG_MAX / x.first && y != s.back()) {
// handle safe breakdown if constraints allow extreme sizes
}
exp *= x.first;
}
result.insert(res);
}
vector<long long> result2;
for(long long x : result){
if (x <= 0) {
result2.push_back(0);
continue;
}
long long buf = 0;
for(long long i = 1; i * i <= x; i++){
if(x % i == 0){
buf += i;
if(i * i != x){
buf += x / i;
}
}
}
result2.push_back(buf);
}
// Descending sort
sort(result2.begin(), result2.end(), greater<long long>());
for(long long x : result2){
cout << x << '\n';
}
return 0;
}