80分求解

P4994 终于结束的起点

开个滚动数组
by DaRK52 @ 2018-11-04 13:09:00


why@[DaRK52](/space/show?uid=81922)
by shitbro @ 2018-11-04 13:11:08


@[larry2004](/space/show?uid=90972) ```cpp #include<iostream> #include<cstdio> using namespace std; int fi[5],m; int main() { scanf("%d",&m); fi[1]=0; fi[2]=1; for(int i=1;;i++) { fi[3]=(fi[1]+fi[2])%m; if(fi[2]==0&&fi[3]==1) { printf("%d\n",i); return 0; } fi[1]=fi[2]; fi[2]=fi[3]; } } ```
by mcyqwq @ 2018-11-04 13:11:21


滚动数组好在哪里
by shitbro @ 2018-11-04 13:11:28


@[larry2004](/space/show?uid=90972) 省空间啊,不然答案一大数组不就爆炸了
by DaRK52 @ 2018-11-04 13:12:12


可是我取了余呀@[DaRK52](/space/show?uid=81922)
by shitbro @ 2018-11-04 13:13:36


@[larry2004](/space/show?uid=90972) emmm我的意思是fi[i%3]这样子来减小fi数组的空间
by DaRK52 @ 2018-11-04 13:15:00


ok
by shitbro @ 2018-11-04 13:16:11


@[larry2004](/space/show?uid=90972) ```c++ #include<iostream> #include<cstdio> using namespace std; int x,y,m,k,t; int main(){ x=1; y=1; k=1; scanf("%d",&m); while(1){ if(y==0&&x==1)break; k++; t=x; x=x+y; y=t; x=x%m; } printf("%d",k); } ```
by suyiheng @ 2018-11-04 13:16:36


```cpp #include<cstdio> #include<iostream> using namespace std; int a[5]; int n; int main() { /*freopen(" ","r",stdin); freopen(" ","w",stdout);*/ cin>>n; a[0]=0; a[1]=1; for(int i=1;;i++) { a[2]=(a[0]+a[1])%n; if(a[2]==1&&a[1]==0) { cout<<i<<endl; return 0; } a[1]=a[2]; a[0]=a[1]; } /*fclose(stdin); fclose(stdout);*/ return 0; } ``` 怎么无限循环了
by shitbro @ 2018-11-04 13:18:56


| 下一页