Nth Magical Number Leetcode Problems Python