CodeChef Easy Fibonacci September Challenge

#include <iostream>
using namespace std;
int main(){
    int  a[202];
    a[0]=0,a[1]=1;
    for(int i=2;i<102;i++){
        a[i]=(a[i-1]+a[i-2])%10;
    }
    //The code below was used to find that fibbonacci sequence will repeat after 60 iterations.
    // for(int j=0;j<101;j++){
    //     for(int i=j+1;i<101;i++){
    //         if(a[i]==a[j]&&a[i+1]==a[j+1]){
    //             cout<<j<<' '<<i<<endl;
    //             cout<<a[j]<<' '<<a[j+1]<<endl;
    //         }
    //     }
    // }
    int t;
    cin>>t;
    while(t--){
        long long n,x;
        cin>>n;
        x=n;
        int cnt=-1;
        while(x>0){
            x>>=1;
            cnt++;
        }
        x=((long long)1)<<cnt;
        x%=60;
        cout<<a[x-1]<<endl;
    }
}

Comments