Last digit of sum of numbers in the given range in the Fibonacci series | Calculate the sum of the first N Fibonacci numbers using Pisano period ; The first two Fibonacci numbers ; Base case ; Pisano Period for % 10 is 60 ; Checking the remainder ; The loop will range from 2 to two terms after the remainder ; Driver code
def fib ( n ) : NEW_LINE INDENT f0 = 0 NEW_LINE f1 = 1 NEW_LINE if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT rem = n % 60 NEW_LINE if ( rem == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT for i in range ( 2 , rem + 3 ) : NEW_LINE INDENT f = ( f0 + f1 ) % 60 NEW_LINE f0 = f1 NEW_LINE f1 = f NEW_LINE DEDENT s = f1 - 1 NEW_LINE return ( s ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT m = 10087887 NEW_LINE n = 2983097899 NEW_LINE final = fib ( n ) - fib ( m - 1 ) NEW_LINE print ( final % 10 ) NEW_LINE DEDENT