Problem Six complete

used series to reduce code into O(1) time.