Using dynamic memory allocation for Collatz