FIBEASY September Long 2019

I also tried an alternative on Python 3.6 . But it showed WA as well probably due to the log() function.Is the log() method broken for all languages? xD
Solution Link: CodeChef: Practical coding for everyone

No it’s simply the log2 function.

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

My AC Solution using inbuilt power function. I just made my log2 function

Inbuilt log function returns float or double so for sufficiently large value the return value is an approximation and not an integer and that on conversion to integer might be less than 1 then the actual value.

If floored value is the answer, then log2() always gives answer more than that floored value,isn’t it?. We need to find a case where log2() is approximating to a value less than actual floored log value.

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