3 ms·
First, find total number of digits of the 3 999 999 999 smallest integers. Let's assume 0 doesn't count. The first 9 numbers have 1 digit each. The next 90 num
by ordinary 15y ago
First, find total number of digits of the 3 999 999 999 smallest integers.
Let's assume 0 doesn't count. The first 9 numbers have 1 digit each. The next 90 numbers have 2 digits each. The next 900 have 3, etcetera. That's 38 888 888 889 digits. Assume one byte per digit. Add a delimiter between every two numbers, plus one delimiter between the 3 999 999 999th and 4 000 000 000th number. That gives us 42 888 888 888 bytes.
Subtract that number from the total file size to get the number of digits in the final number. Say the file is 40 GiB. 40 GiB is 42 949 672 960 bytes. That leaves 60 784 072 bytes (or digits) for the 4 000 000 000th number.
Add 1 to that number to make sure it's bigger than any of the numbers that can possibly be in the file. Now construct a number of 60 784 073 digits by whatever method you wish.