其中一个建议是使用其他类型。
这是整数类型、大小和限制的列表。
--------------------------------------------------------------------------------------
|type |size (B)|Limits |
--------------------------------------------------------------------------------------
|long long |8 |–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807|
--------------------------------------------------------------------------------------
|unsigned long long |8 |0 to 18,446,744,073,709,551,615 |
--------------------------------------------------------------------------------------
|int |4 |–2,147,483,648 to 2,147,483,647 |
--------------------------------------------------------------------------------------
|unsigned int |4 |0 to 4,294,967,295 |
--------------------------------------------------------------------------------------
|short |2 |–32,768 to 32,767 |
--------------------------------------------------------------------------------------
|unsigned short |2 |0 to 65,535 |
--------------------------------------------------------------------------------------
|char |1 |–128 to 127 |
--------------------------------------------------------------------------------------
|unsigned char |1 |0 to 255 |
--------------------------------------------------------------------------------------
注意 long
和int
通常是相同的大小。
请注意,这些限制在所有架构上都不相同,标准只保证关于可变大小的两件事:
- 1 =
sizeof(char)
=sizeof(unsigned char)
- 2 =
sizeof(shor)
= sizeof(unsigned short)
<= sizeof(int)
= sizeof(unsigned int)
<= sizeof(long)
= sizeof(unsigned long)
<= sizeof(long long)
=sizeof(unsigned long long)
另一种选择是使用bigint库,但是在这种情况下,计算会花费更多时间,但会很合适。