Solution to UVa 3n+1 problem