One of the suggests would be to use some other type.
Here is a list of integer types, sizes and limits.
--------------------------------------------------------------------------------------
|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 |
--------------------------------------------------------------------------------------
Note long
and int
usually are the same size.
Note those limits aren't the same on all architectures standart guarantee only two things about variable sizes:
- 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)
Another option is to use bigint library, however in this case calculations will take more time but will fit.