约瑟夫环求最后剩余的元素
摘要:
递推公式f[1]=0;f[i]=(f[i-1]+m)%i; (i>1)# include# include# include# include# include# includeusing namespace std;# define maxn 1000001int main(){ int n,m; while(cin>>n>>m) { int ans=0; for(int i=2;i<=n;i++) ans=(ans+m)%i; printf("%d\n",ans+1); } return 0;}View ... 阅读全文
posted @ 2014-02-26 10:29 asif 阅读(247) 评论(0) 推荐(0) 编辑