How to represent a large number in way so that it requires a smaller memory space

105 Views Asked by At

I have $25+$ digit numbers which I need to store in a manner that require least amount of memory space but at the same time represents the number exactly For example: the number $34359738418$ can also be represented as $2^{35}+50$ which requires a smaller memory (has fewer bytes). Would appreciate if someone can guide me towards a method to represent extremely large number

1

There are 1 best solutions below

2
On

Unless your numbers have special known properties (which you don't tell us clearly) and belong to a specific subset of large numbers, this is impossible. Because with $b$ bits you can represent $2^b$ distinct numbers, not less, not more, and if $b<b'$, then $2^b<2^{b'}$. If you make some of the numbers shorter, others must become longer.


On another hand, if your numbers are not random but pseudo-random, and you know the generator, then with constant storage you will be able to recompute as many numbers as you want.