FIBEASY - Unofficial Editorial

try

1
134

your output is -3 which should be 3

Also, on my machine, your solution crashes for

1
1
1 Like

No man, Here is my AC solution using builtin log2l() and exp2l() function :blush:

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;
}

Why not??? Builtin function better to use. Here is my AC solution using builtin log2l() and exp2l() function :blush:

No man, Here is my AC solution using builtin log2l() and exp2l() function :blush:

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;
}

That’s why you should use builtin log2l() and exp2l() functions, Here is my AC solution using builtin log2l() and exp2l() function :blush:

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

You should use builtin function log2l() and exp2l(), Here is my AC solution using builtin log2l() and exp2l() function.

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

CODE:

#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);
  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;
}

:joy::joy::joy::joy::joy: Most Efficient Coder…:rofl::joy:

1 Like

Whats wrong in this code. I have passed first 2 test cases but got WA in the last one.
https://www.codechef.com/viewsolution/26627353

I have compared the above code’s output by Running a test for 100000 random numbers between 1 and 10^18 with ‘CodeChef: Practical coding for everyone’ (which is AC) on my Computer and got no difference.

Please Help !!!

Try the testcase here.

1 Like

Using log2() will lose precision for the following testcase:

1
18014398509481983

Output should be 9.

2 Likes

could you please check where my solution is wrong it is failing higher test cases
link to solution: https://www.codechef.com/viewsolution/26632818
for testcase
1
18014398509481983
my solution giving 9 as output
Thanks

It seems to fail the testcase:

1
36028797018963968

(answer should be 3)

my solution output is also 3check

Interesting - I’m getting 4 from yours on my machine.

someone is saying that log2() has some precision errors the conflicting answers may be due to that??

That’s the most likely explanation :slight_smile:

Thanks , for your immediate response ,
Debugged the solution for hours in the (10 days) dont know the where the solution fails
that just because of built in log2() :disappointed_relieved:

1 Like

can someone explain me this part of the editorial---->"Now let’s get to the second part of the problem. Basically, we’re dividing our array AA repeatedly by 2. So we can make an observation that the number which would be the highest power of 2 in the array would remain until the end."
how we will find which element will be the last remaining element in the array?