int lastRemaining(int n, int m){ int f = 0; for(int i = 1;i <= n;i++)f = (f + m)%i; //0 1 2 3 4 //f = 0, f = 0,f = 1, f = 0,f = 3 return f; }