FIBEASY September Long 2019

that’s correct I m facing the same problem I m not able to debug for the higher rang of values

Based on @amoghk 's very helpful post here, the following testcase might fail for some of you:

1 
576460752303423487

where did he used log2 function?

Here is my solution, log function perfectly working.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);

  int f[60] = {0};
  f[1] = 1;
  for (int i = 2; i <= 60; i++) {
    f[i] = (f[i - 1] + f[i - 2]) % 10;
  }

  int t;
  cin >> t;
  while (t--) {
    ull n;
    cin >> n;
    n = log2l(n);
    n = exp2l(n) - 1;
    cout << f[n % 60] << "\n";
  }
  return 0;
}
1 Like

No i mean this question could be solved using the builtin functions except the log2

1 Like

that is also a point please some one enlight us on this very unusual kind of debugging

https://www.codechef.com/viewsolution/26625992

Here is the fixed answer

I just did this

        ll index=pow(2,y);
        //cout<<index<<endl;
        cout<<findLastDigit(index%60 -1)<<endl;

I know it’s dumb to ask because I’m beginner in ds and algo. Where you learnt that 10^8 is max memory allocation for the array?

Honestly… i think i read somewhere on internet…i don’t remember where :laughing:

Maximum size of the array: We must be knowing that the maximum size of array declared inside the main function is of the order of 10^6 but if you declare array globally then you can declare its size upto 10^7

Ref: Geeksforgeeks

According to Geeks for Geeks, it should be 10^7. Isn’t right??

Use exp2l() function, Its better than pow() function.

    cin >> n;
    n = log2l(n);
    n = exp2l(n) - 1;
    cout << f[n % 60] << "\n";

You can use up to 10^8. I also read it somewhere :sweat_smile::sweat_smile: But that you have to declare globally. And I also tried it creating the global array with size 10^8. And up to 10^6 is advised inside the function.

Although the size of array also depends upon whether you want to create integer array or character array. Along with that it also depends on your hardware.

Using log2() will give WA for the following testcase:

1
18014398509481983

Output should be 9.

have you even tried on his solution?
works fine riNeF6 - Online C++0x Compiler & Debugging Tool - Ideone.com

Got it. I was doing index-1 % 60. Cheers.

1 Like

Was meant as an announcement for the people who were wondering why log2() was not working, I’m the problem setter. Replied on your comment by mistake, this wasn’t supposed to be a reply.

That’s awesome ! :smile:

How did you come up with this logic bro:)