I like to solve programming contest problems once in a while, and sometimes, while working on it, I've been forced to switch from C++
to either Java or Python (and more recently to Haskell) to use the multi-precision integer support of those languages, a.k.a BigNums
or BigIntegers
.
Both Python and Haskell have this feature in the very core of the language, meanwhile in Java you have to create an instance of the
BigInteger
class an invoke its operation methods in chain, thus creating some verbose expressions:
1 2 3 | // n * n + (n * (n + 1)) / 2 n.multiply(n).add(n.multiply(n).divide(BigInteger.valueOf( 2 ))); |
I've been always intrigued by how BigInt works; this gives me a excuse to delve around this topic, so I decided to craft my own C++ BigInt class to deal with this issue just for fun.