Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- using namespace std;
- class Fibonacci final {
- public:
- static int get_last_digit(int n) {
- assert(n >= 1);
- int a = 0, b = 1;
- int last_digit;
- for (int i = 2; i <= n; i++) {
- last_digit = (a + b) % 10;
- a = b;
- b = last_digit;
- }
- return last_digit;
- }
- };
- int main(void) {
- int n;
- std::cin >> n;
- std::cout << Fibonacci::get_last_digit(n) << std::endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement