B*********h 发帖数: 800 | 1 ☆─────────────────────────────────────☆
newnewlife (newlife) 于 (Fri Jan 19 16:55:23 2007) 提到:
圆圈上顺时针排列着1,2,3,....2000 这
2000个数. 从1开始,顺时针隔一个拿走一个(1最先被拿走,下一个是3被拿走).
问最后剩下是哪一个数字.
this is a question from 精华区 and already have a solution.
here i just want to sovle it using recursion.
the recursion formula is:
f(2n) = 2f(n); since if it is even then the odds are eliminated first and
start with the game starting with the first even number again.
f(2n+1)=2*{ [f(n)+1]%n}; after first round the game st |
|