[LeetCode] Hexadecimal and Hexatrigesimal Conversion

3602. Hexadecimal and Hexatrigesimal Conversion

You are given an integer n.

Return the concatenation of the hexadecimal representation of n2 and the hexatrigesimal representation of n3.

A hexadecimal number is defined as a base-16 numeral system that uses the digits 0 – 9 and the uppercase letters A - F to represent values from 0 to 15.

A hexatrigesimal number is defined as a base-36 numeral system that uses the digits 0 – 9 and the uppercase letters A - Z to represent values from 0 to 35.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
string helper(int n, int mod) {
string res = "";
while(n) {
int m = n % mod;
n /= mod;
res.push_back(m < 10 ? m + '0' : m - 10 + 'A');
}
reverse(begin(res), end(res));
return res;
}
public:
string concatHex36(int n) {
return helper(n * n, 16) + helper(n * n * n, 36);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/07/06/PS/LeetCode/hexadecimal-and-hexatrigesimal-conversion/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.