Advertisement
TwITe

Untitled

Sep 8th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. using namespace std;
  4.  
  5. class Fibonacci final {
  6. public:
  7.     static int get_last_digit(int n) {
  8.         assert(n >= 1);
  9.         int a = 0, b = 1;
  10.         int last_digit;
  11.         for (int i = 2; i <= n; i++) {
  12.             last_digit = (a + b) % 10;
  13.             a = b;
  14.             b = last_digit;
  15.         }
  16.         return last_digit;
  17.     }
  18. };
  19.  
  20. int main(void) {
  21.     int n;
  22.     std::cin >> n;
  23.     std::cout << Fibonacci::get_last_digit(n) << std::endl;
  24.     system("PAUSE");
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement