AMIFIB - Editorial

admin please answer!!!

@junior94 this is not a platform to test language skills. If algorithmic skills were to be tested, the limits would have been within 10^18.

1 Like

@all : I am the setter for this problem .

You could generate all fibonacci numbers till 1000 digits ( no modulo is needed like the tester did ) and store them . The time limit and memory limit was conducive to do such a computation . You could store them in an array and do binary search for solving each query .

Or , otherwise you could use the fibonacci number property that 5nn + 4 or 5nn - 4 or both are perfect square to solve it . My solution ( setter’s solution ) uses it .

There were indeed test cases which had near about 1000 digits .

3 Likes

@rishul_nsit, I didn’t say it was a platform to test language skills, I only said that users usually take advantage of their language features. In cook offs it’s always better to do a task in the shortest way possible. I won’t deny that python and java had a significant advantage over C and C++ but this is not the first time that a question regarding BigInteger is appearing and possibly not the last either. But I must agree with @sikander_nsit statement too, for one of the easiest problems in the cook off, it required a significant amount of coding.

Can you explain how the tester is storing 1000 digit numbers into a set of unsigned long long !

3 Likes

What’ the problem with my solution??? It was not accepted but I compared the output with others solutions which are accepted. I took large numbers (like 354224848179261915075 fib(100)) also… My code works fine… but when I submitted,its giving wrong answer… http://www.codechef.com/viewsolution/3000210… Please help me…

@junior94 what I meant was such questions should appear in Long contests and not the cook offs

Those who know java or python well can easily solve it…
I applied the logic that if 5nn + 4 or 5nn - 4 is a perfect square number then the number would be fibinoci number…
but that will not fit in the normal data types…this may be an easy problem…but not a confidence booster for newbies like me who are learning to swim in the pool of c++…:frowning:

As described, the method is based on hashing technique. Numbers which are bigger than ULL are automatically stored as remainders of this max value. Now when you take the input as string and convert it to number again and if IT ALSO generates the same remainder (after being ‘wrapped’ around ULL_MAX) will be found in the set, otherwise not.

This obviously assumes that there are no two numbers (one of which is Fibonacci while other not) that give same remainder, atleast in the given constraints). This technique however, doesn’t guarantee solution and may or may not work.

1 Like

My solution is perfect… I ran the tester’s solution and it starts generating wrong fibonacci numbers after F(94)… So my solution was not get accepted… Tester’s F(95) - 1293530146158671551… My F(95) - 19740274219868223167…

@all : Tester is not storing big numbers . He is storing number mod 2^64-1 . Since numbers overflow by themselves he is not doing modulo operation . While this approach may pass , this cannot guarantee correctness , and I am not surprised that it fails some of the test cases that users are talking about .

4 Likes

Was this done in purpose so Tester’s solution would pass? Because while hashing is a nice and general technique, it shouldn’t be used in such “tricky”/improvised way as it might mislead some beginners as to when to use hashing or not… The fact that the test cases were “good” enough so that this “natural hashing” technique would pass makes me think that this was done in purpose as this solution can’t even guarantee correctness…

5 Likes

@kurumua : I made the problem statement and test cases . The tester wrote and submitted his code after the test cases were posted . I discussed with the tester that “hashing” on any particular “modulus” can’t guarantee correctness . However since the output for the test cases was generated by my solution , the correctness was guaranteed . And we could not have prevented all possible “modulus” for hash from passing the test cases .

@kuruma : I agree that giving the “hashing” based solution to “editorialist” as a reference solution is highly misleading especially beginners . If you want you can write to codechef admin’s at [email protected] to get the “tester’s” solution replaced . I had already raised this issue during the problem setting process .

2 Likes

@nipun_poddar : There is no issue with test cases . There is definitely an issue with “tester’s” solution .

Fast doubling method ! Thanks for a new concept :slight_smile:

@vineetpaliwal, thanks for your reply and cofirmation :slight_smile:

I will definitely e-mail codechef admins regarding this matter as soon as possible for me :smiley:

By the way, the problem was interesting and your idea for solving it was also very good :slight_smile:

Best,

Bruno

1 Like

I ran the tester’s code on my system, I am very sad to see that the output is ‘YES’ for all numbers greater than 10^64 :frowning:

1 Like

I don’t get it. You say that you were aware of tester’s approach and you raised a concern but don’t you think generating the test cases that would not allow tester’s solution to pass, for this particular problem, was easy?

@sid_gup : Generating test cases for one particular modulo hash is easy , but nothing can be done in general as one may use any particular for modulus for hashing .

Isn’t it true that the tester’s solution is showing ‘YES’ for all inputs greater than 10^64?