【剑指offer】圆圈中最后剩下的数(python)

class Solution:
    def LastRemaining_Solution(self, n, m):
        # write code here
        # f(n)=(f(n-1)+m)%n,递归不可以AC,用迭代,从f(2)算到f(n)
        if n == 0: return -1
        index = 0
        for i in range(2,n+1):
            index = (index + m) % i
        return index