How to find nth number of a sequence