FIBEASY - Editorial

you were right!!
my problem was with the log function.
my idea was almost same as the editorial except i didn’t use the periodicity part…
i observed a relation among the numbers

1 Like

@as_max_rider Well its good that you figure it out. :slight_smile:

hey everyone. cant i avoid TLE using this method i have done?


I am seriously facing trouble understanding that. Can anybody give me an easy explanation.

Or handily you can avoid any sort of log function - use the bit_length() function of int class.

1 Like

my code
is partially correct, is it wrong to use log2(n) for large inputs…?
Thanks in advance…!

This solution seems to give 0 for the testcase:


In general, it’s a bad idea to use floating point where an integer solution is expected (though it’s OK sometimes e.g. sqrt when testing for primality, etc). People have come up with testcases where the use of log gives the wrong answer for FIBEASY - see e.g. here and the post linked from that post.

1 Like

Why website shows runtime error of problem code fibeasy?

int main(){
int T, N, j;
int f[50];
int first = 0,second = 1;
f[0] = first;
f[1] = second;
for(int i=2;i<N;i++){
f[i] = first + second;
first = second;
second = f[i];
for(int i=0;i<N;i++)
f[i] = f[i]%10;
for(int i=1;i<N;i=i+2){
f[j] = f[i];
N = N/2;
Can anybody review this solution of mine and tell me why is it showing TLE and how can i make it more efficient?

can anyone tell why my code (SEE THIS) is giving partially correct for subtask1 and wrong answer for subtask2

So we should basically know that fibonacci no.s mod 10 are periodic with period 60. So vague, isn’t it?
Or do they expect us to figure it out?

This :slight_smile:

1 Like

Well I read about Pisano period, its written that its not possible to manually calculate it for a given integer. (here)
Should we print the values and check ? Sounds very tedious and counterintuitive.

I can’t remember what I did - I either printed out the values, spotted the pattern and deduced why; or the other way around :slight_smile:

The logic behind it is fairly simple:

1 Like

Thanks a lot. U explained it in a nice way :smiley:

Can any body know that Fibonacci numbers mod 10 is periodic when they encounter the problem for the first time ?

I’m getting WA in subtask 2. I’m not getting what is wrong.
Here is my code
Any help would be appreciated.

FIBEASY - Editorial :slight_smile: