Fibonacci Sum of Large Numbers(Only Last Digit to be Printed)

后端 未结 5 1972
死守一世寂寞
死守一世寂寞 2020-12-31 12:44

I have been trying to come out with a solution regarding the problem of finding the last digit of the sum of large n Fibonacci series. I have been able to pass several test

5条回答
  •  无人及你
    2020-12-31 13:36

    Actually it's even easier than Niall answer

    int get_fibonacci_sum_last_digit(long long n) {
        const int kPisanoSize = 60;
        int rest = n % kPisanoSize;
        int preparedNumbers[kPisanoSize] = {0, 1, 2, 4, 7, 2, 0, 3, 4, 8, 3, 
            2, 6, 9, 6, 6, 3, 0, 4, 5, 0, 6, 7, 4, 2, 7, 0, 8, 9, 8, 8, 7, 
            6, 4, 1, 6, 8, 5, 4, 0, 5, 6, 2, 9, 2, 2, 5, 8, 4, 3, 8, 2, 1, 
            4, 6, 1, 8, 0, 9, 0};
        return preparedNumbers[rest];
    

    }

提交回复
热议问题