Skip to content

Instantly share code, notes, and snippets.

@aadimator
Created July 19, 2016 05:50
Show Gist options
  • Save aadimator/370fb465f6732561089e84ed889129a2 to your computer and use it in GitHub Desktop.
Save aadimator/370fb465f6732561089e84ed889129a2 to your computer and use it in GitHub Desktop.
The Last Digit of a Large Fibonacci Number
#include <iostream>
int get_fibonacci_last_digit(long long n) {
int first = 0;
int second = 1;
int res;
for (int i = 2; i <= n; i++) {
res = (first + second) % 10;
first = second;
second = res;
}
return res;
}
int main() {
int n;
std::cin >> n;
int c = get_fibonacci_last_digit(n);
std::cout << c << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment