解题思路:
注意事项:
参考代码:
#include<stdio.h>
int main() {
int n,m;
while(scanf("%d %d",&n,&m)!=EOF) {
int s=0;
for(int i=2; i<=n; i++) {
s=(s+m)%i;
}
printf("%d\n",s+1);
}
return 0;
}
-------------------------------------------------------------------------------------------------------------
int main() {
int n,m;
int table[200];
int baoShu;
int index;
int count;
while(scanf("%d %d",&n,&m)!=EOF) {
count=n;
baoShu=0;
index=0;
for(int i=1; i<=n; i++) {
table[i]=1;
}
while(count>1) {
index++;
baoShu++;
if(index>n) {
index=1;
}
while(table[index]==0) {
index++;
if(index>n)
index=1;
}
if(baoShu==m) {
table[index]=0;
baoShu=0;
count--;
}
}
for(int i=1; i<=n; i++) {
if(table[i]==1)
printf("%d\n",i);
}
}
return 0;
}
0.0分
1 人评分