Added detailed analysis for problem 6.
Fixed a stack overflow when n is large.