I was just wondering which will the best BigInteger class in C++ for programming contests which do not allow external libraries?
Mainly I was looking for a class which could be used in my code( I will of course write it on my own, on similar grounds ).
The primary factors which I think are important are( according to their importance ):
Arbitrary length numbers and their operations should be supported.
Should be as small as possible, code-wise. Usually there's a limit on the size of the source code which can be submitted to ~50KB, so the code should be ( much )smaller than that.
Should be as fast as possible. I read somewhere that bigInt classes take
O( log( n ) )
time, so this should have a similiar complexity. What I mean is that it should be as fast as possible.
So far I've only needed unsigned integer big numbers for codechef, but codechef only gives 2KB, so I don't have the full implementation up there anywhere, just the members needed for that problem. My code also assumes that
long long
has at least twice as many bits as aunsigned
, though that's pretty safe. The only real trick to it is that differentbiguint
classes may have different data lengths. Here's summaries of the more interesting functions.I also made specializations for multiplication, divide, modulo, shifts and others for
std::integral_constant<unsigned int, Value>
, which made massive improvements to my serializing and deserializing functions amongst others.