Did you know! There is no limit to the number of python ints that can be represented! !! Since int in C is 32bit, it can only represent up to 2147483647. Even the long long used when dealing with large numbers can only represent 64 bits, that is, 9223372036854775807. On the other hand, ints in python are infinite.
When I hear that there is no upper limit, it is humanity that makes me want to handle huge numbers of feces. To see if there is really a limit, and if there is no limit, how long the calculation time is I did a simple experiment! Actually check the time required for calculation and the time required for display based on the following code.
test.py
num_list, time_list = [], []
for i in range(9):
start = time.time()
ans = 10 ** (10 ** i)
end = time.time()
print('Elapsed time to calculate 10 ** {} is {}'.format(10 ** i, end - start))
num_list.append(10 ** i)
time_list.append(end - start)
plt.plot(num_list, time_list)
plt.show()
The experimental results are shown in the table below! It's hard to understand, but the numbers on the far left of the table represent the $ n $ part of $ 10 ^ n $. Therefore, 100 in the top column of the table is the time it took to calculate and display $ 10 ^ {100} $.
calculate[s] | print[s] | |
---|---|---|
100 | 0.000 | 0.000 |
1000 | 0.000 | 0.000 |
10000 | 0.000 | 0.002992 |
1e05 | 0.01562 | 0.1396 |
1e06 | 0.1562 | 13.27 |
1e07 | 5.985 | 1324 |
1e08 | 221.7 | - |
1e09 | 8791 | - |
Even such a large number can be calculated properly, but it takes a lot of time. When $ n $ increases 10 times, the calculation time will increase 40 times and the display time will increase 100 times. By the way, even if you say "display", the value is too large to display it on the console due to a bug (naturally). Also, print 1e08 and 1e09 are No data because it took too long and I got tired of it. The figure that the bug is displayed from 0 →![Print_bag.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/419937/c813ae25-9631-1129- 6c24-2b0c1afd528e.png)
The graph is below. As I mentioned above, it looks like it will increase exponentially!
At first I started thinking about calculating Googolplex, but in the first place
Recommended Posts