深圳观澜逸丰租车:1-1993这1993个数,写在个圆圈上。之后把1擦掉留2和3。擦掉4留5和6...类推下去。求最后剩的一个数?

来源:百度文库 编辑:杭州交通信息网 时间:2024/03/29 02:10:09
原题:有1-1993这1993个数,用顺时针循环写在一个圆圈里。之后把1擦掉、留下2和3。擦掉4,留下5和6......以此类推继续下去。问最后剩下的一个数是多少?

1992

1993之前能被3整除的是1992
之后1993被删除,所以是1992

不知道

用程序算出来是584,用循环链表实现的:
#include<stdio.h>
#include<stdlib.h>
struct node{
int x;
struct node *next;
};

int main()
{
int i;
struct node *head,*p,*q;
p=head=(struct node *)malloc(sizeof(struct node));
p->x=1;
p->next=NULL;
q=p;
for(i=2;i<1994;i++){
p=(struct node *)malloc(sizeof(struct node));
p->x=i;
q->next=p;
q=p;
}
q->next=head;
i=0;
p=head;
while(p!=q){
if(i==0){p=p->next;free(q->next);q->next=p;}
else {if(i==2)i=-1;q=p;p=p->next;}
i++;
}
printf("%d",p->x);
free(p);
}

好象最后应该剩下两个数?????????????