#include //#include //int get_fibonacci_last_digit_naive(int n) { // if (n <= 1) // return n; // // int previous = 0; // int current = 1; // // for (int i = 0; i < n - 1; ++i) { // int tmp_previous = previous; // previous = current; // current = tmp_previous + current; // } // // return current % 10; //} int get_fibonacci_last_digit_optimized(int n) { if (n <= 1) return n; int fibLastDigitArray[n]; fibLastDigitArray[0] = 0; fibLastDigitArray[1] = 1; for (int i = 2; i < n + 1; i++) { fibLastDigitArray[i] = (fibLastDigitArray[i - 1] + fibLastDigitArray[i - 2]) % 10; } return fibLastDigitArray[n]; } //TEST(FibLastDigitTest, Zero) { // ASSERT_EQ(get_fibonacci_last_digit_naive(0), 0); //} // //TEST(FibLastDigitTest, One) { // ASSERT_EQ(get_fibonacci_last_digit_naive(1), 1); //} // //TEST(FibLastDigitTest, Three) { // ASSERT_EQ(get_fibonacci_last_digit_naive(3), 2); //} // //TEST(FibLastDigitTest, Forty) { // ASSERT_EQ(get_fibonacci_last_digit_naive(40), 5); // ASSERT_EQ(get_fibonacci_last_digit_optimized(40), 5); //} // //TEST(FibLastDigitTest, ThreeThreeOne) { // ASSERT_EQ(get_fibonacci_last_digit_optimized(331), 9); // ASSERT_EQ(get_fibonacci_last_digit_optimized(327305), 5); //} int main() { int n; std::cin >> n; int c = get_fibonacci_last_digit_optimized(n); std::cout << c << '\n'; }