algorithm for writing a billion numbers to file