#include
using namespace std;
#define ll long long int
intf1(inta,intb)
{
intc=new int*[2];
c[0]=new int[2];
c[1]=new int[2];
c[0][0]=(a[0][0]*b[0][0]+a[0][1]*b[1][0]);
c[0][1]=(a[0][0]*b[0][1]+a[0][1]*b[1][1]);
c[1][0]=(a[1][0]*b[0][0]+a[1][1]*b[1][0]);
c[1][1]=(a[1][0]*b[0][1]+a[1][1]b[1][1]);
return c;
}
intfun(inta,int n)
{
if(n==1)
return a;
if(n%2==0)
return f1(fun(a,n/2),fun(a,n/2));
else
return f1(a,fun(a,n-1));
}
int main()
{
int t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
int**a=new int[2];
a[0]=new int[2];
a[1]=new int[2];
a[0][0]=0;
a[0][1]=1;
a[1][0]=1;
a[1][1]=1;
a=fun(a,n-1);
cout<<(a[0][0]+a[0][1])%1000000007<<endl;
}
}
Above is my code for FastFib problem.TLE is shown on submission.Please tell me if their is an error in the code.
TLE is shown in FastFib problem in the code below
@Amit.sharma send me your code by saving it in (https://ide.codingblocks.com/), here it is not getting paste correctly.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.