Regarding time out in code

You don’t need to make n2=34.
We can use array to finish this question, like this:

int a[1001];
memset(a,0,sizeof(a));
while(!EOF){
    a[0]=a[1]=1;
    cin>>n;
    for(int i=2;i<=n;i++){
        a[i]=a[i-1]+a[i-2];
    }
    cout<<a[n];
}

Leave a Comment