Time limit is:1 sec
#include
#include
#include
using namespace std;
int main() {
int t;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
int n;
scanf("%d",&n);
int f[n];
f[0]=0;
f[1]=1;
for(int i=2;i<n;i++)
{
f[i]=f[i-1]+f[i-2];
}
vector<int> d;
for(int i=0;i<n;i++)
{
d.push_back(f[i]%10);
}
vector<int> e;
while(d.size()>1)
{
for(int i=1;i<d.size();i=i+2)
{
e.push_back(d[i]);
}
d.clear();
for(int i=0;i<e.size();i++)
{
d.push_back(e[i]);
}
e.clear();
}
for(int i=0;i<d.size();i++)
{
printf("%d",d[i]);
}
}
return 0;
}
The following code is taking 1.01 sec how to resolve it?