solved the 3n+1 using segment tree and dynamic programming