Hexagonal Numbers — Solution & Editorial
Apply the closed form directly — derive it by pairing/telescoping if unfamiliar.
Complexity: O(1)
Watch out: The result overflows 32-bit — use 64-bit (or big) integers.
Apply the closed form directly — derive it by pairing/telescoping if unfamiliar.
Complexity: O(1)
Watch out: The result overflows 32-bit — use 64-bit (or big) integers.