力扣 https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/
class Solution {
public:
int cc(int n,int m){
if(n==1)
return 0;
return (m+cc(n-1,m))%n;
}
int lastRemaining(int n, int m) {
return cc(n,m);
}
};
以下内容出自力扣
我们有n个数,下标从0到n-1,然后从index=0
开始数,每次数m个数,最后看能剩下谁。我们假设能剩下的数的**下标**为y,则我们把这件事表示为
f(n,m) = y
这个y到底表示了啥呢?注意,y是下标,所以就意味着你从index=0
开始数,数y+1个数,然后就停,停谁身上谁就是结果。
行了,我们假设f(n-1,m)=x
,然后来找一找f(n,m)
和f(n-1,m)
到底啥关系。
f(n-1,m)=x
意味着啥呢