-4

您需要将多少字节存储2^57,885,161 - 1为整数?

4

2 回答 2

6

Assuming we're doing two's complement and that 8 bits is equal to one byte; we'd need at least (57,885,161+7)/8 bytes.

If you needed a simple way to possibly explain it is by using mathematical induction that says 2^32 - 1 is the maximum number that a 32-bit integer would represent, and 32 is a base of 2 that is divisible by 8, our assumed number of bits per byte. 2^32 - 1 would be 4 bytes.

Extending this definition of assumptions you have the number 2^57885161 which isn't divisible by 8, but adding 7 to it is. So you're left with 2^57885168, and when you divide it by 8 you get the resultant 7235646 bytes.

This is just an explanation of GregS's comment.

于 2013-02-10T00:26:31.303 回答
3

答案很大程度上取决于您将如何处理它。如果您正在编写一个专门使用梅森素数的程序,您可能只需要四个字节来存储它,并理解它代表梅森素数指数。

如果要将其存储为典型的未压缩“大整数”,则大约需要 7235646 个字节(ceildiv(57885161, 8))。有些格式比其他格式更有效。例如,由于格式开销(因为 Python 使用 30 位数字) ,Pythonlong格式使用 7718048 字节将此数字存储在我的机器 ( ) 上。(2**57885161 - 1).__sizeof__()

于 2013-02-10T00:18:03.710 回答