这是一个好的 C++用于编程竞赛的 BigInteger 类?
我只是想知道对于不允许外部库的编程竞赛,C++ 中最好的 BigInteger 类是哪个?
主要是我正在寻找一个可以在我的代码中使用的类(基于类似的理由,我当然会自己编写它)。
我认为重要的主要因素是(根据其重要性):
应该支持任意长度的数字及其运算。
就代码而言,应该尽可能小。通常,可以提交的源代码的大小有~50KB 的限制,因此代码应该比这个小得多。
应该尽可能快。我在某处读到 bigInt 类需要
O( log( n ) )
时间,因此这应该具有类似的复杂性。我的意思是它应该尽可能快。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,我只需要 codechef 的无符号整数大数字,但 codechef 只提供 2KB,所以我在任何地方都没有完整的实现,只有该问题所需的成员。我的代码还假设
long long
的位数至少是unsigned
的两倍,尽管这是相当安全的。唯一真正的技巧是不同的biguint类可能有不同的数据长度。这里总结了一些更有趣的功能。我还专门针对
std::integral_constant
进行了乘法、除法、取模、移位等操作,这对我的序列化和反序列化函数进行了大规模改进除其他外。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.