my solution is failing the test case 1234 12345 in the output and it is giving output 2 instead of correct output 8 although some of the test cases in the question sample have passed . please point out my mistake. thank you.
#include <bits/stdc++.h>
using namespace std;
int calc_fib(long long n) {
long long int m, o = 0, p = 1, q = 1;
m = (n+2) % 60;
for(long long int i = 2 ; i <= m ; i++) {
q = o + p;
o = p;
p = q;
}
//if m=0 then q should be 0 and not 1 so base case
if(m == 0) q = 0;
return q;
}
int main() {
long long a, b;
cin>>a>>b;
int result1 = calc_fib(b);
int result2 = calc_fib(a-1);
int final_result = ((result1%10) - (result2%10) + 10) % 10;
cout<<final_result;
return 0;
}