Ad
  • Custom User Avatar

    Nope. First number is 1

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hello. I think you're wrong and you got overflow. Because Fibonacci's sequence can't take negative value. It begins with 1, 1, 2, 3, 5, 8... and so on.

    You have negative value, because value in 300th is "222232244629420445529739893461909967206666939096499764990979600" this value bigger than types integer or long can store (maybe BigInteger or BigDecimal, but I haven't tested it).

    In Java or C/C++, for example, sign integer type (32 bit) max value is: 2147483647.
    signed long (long long in C/C++) type (64 bit) max value is: 9223372036854775807 (note that signed 64 bit is smaller than 300th Fibonacci number). What happens if give more than can be stored?

    If I'll try making something like this in Java:

    int i = Integer.MAX_VALUE + 1;
    System.out.println(i);
    

    I will get overflow, in this case "i" will store "-2147483648". Why "-2147483648", not "2147483647"? Because the first bit is responsible for the sign.

    2147483647 in binary:
    0|1111111 11111111 11111111 11111111
    2147483647 + 1 in binary:
    1|0000000 00000000 00000000 00000000 
    

    You can read more about signed/unsigned numbers here and here

  • Custom User Avatar

    I did not realize, what it affect, but I swapped 'expected' and 'actual'.

  • Custom User Avatar

    Replaced test cases from static to random values.