话说我就单纯的想练一下链表,没想明白每次暴力的时候都要申请空间,很浪费时间,以至于我超时,所以寡断打表了,下面是我暴力打表的代码!!!
#include<iostream>
using namespace std;
struct node
{
int num;
node *next;
};
node *head,*p,h;
int main()
{
int n;
for(int n=3;n<=150;n++)
{
int temp;
for(int i=2;i<10000;i++)
{
h.next=NULL;
head=&h;
p=head;
for(int po=1;po<=n;po++)
{
p->next=(struct node*)malloc(sizeof(struct node));
p=p->next;
p->num=po;
if(po!=n)
p->next=NULL;
else
p->next=head->next->next;
}
p=head;
p->next=p->next->next;
p=p->next;
temp=i;
// cout<<i;
// system("pause");
while(p!=p->next)
{
for(int j=1;j<=temp-2;j++)
p=p->next;
// cout<<p->next->num<<" "<<endl;
p->next=p->next->next;
if(temp!=1)
p=p->next;
}
if(p->num==2)
{
printf(",%d",i);
break;
}
}
}
system("pause");
return 0;
}
#include<iostream>
using namespace std;
int a[180]={1,1,1,2,5,2,4,3,11,2,3,8,16,4,21,6,5,2,11,20,34,8,15,10,7,13,11,13,45,18,23,8,3,2,25,75,42,13,5,23,13,50,16,18,89,38,8,39,30,29,38,7,45,23,137,46,63,17,48,5,46,34,140,33,39,2,28,29,79,33,48,3,10,46,120,6,37,17,8,44,15,160,20,35,144,104,179,153,24,8,265,19,9,62,7,139,19,44,93,182,27,158,185,193,17,82,3,11,43,55,21,41,146,29,80,59,8,29,66,19,160,59,28,129,127,120,72,45,157,2,63,127,81,318,513,98,28,32,231,236,411,26,45,5,303,228,66,9,205,65,39};
int main()
{
int n;
while(cin>>n,n)
cout<<a[n]<<endl;
return 0;
}