Last Digit of a Large Fibonacci Number fast algorithm
问题 I'm trying to solve Fibonacci using java, but my code takes so long with big numbers. Problem Description Task. Given an integer 𝑛, find the last digit of the 𝑛th Fibonacci number 𝐹𝑛 (that is, 𝐹𝑛 mod 10). Input Format. The input consists of a single integer 𝑛. Constraints. 0 ≤ 𝑛 ≤ 10⁷. Output Format. Output the last digit of 𝐹𝑛 . My code: public class FibonacciLastDigit { private static int getFibonacciLastDigitNaive(int n) { if (n <= 1) { return n; } BigInteger first = BigInteger.ZERO;