Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Uses python3
- # slow from the definition algo
- def calc_fib(n):
- if n <= 1:
- return n
- return calc_fib(n - 1) + calc_fib(n - 2)
- # faster storing values in List as we go along
- l = [0, 1]
- def fib_faster(n):
- if not 1 < n:
- 0
- else:
- [l.append(l[_ - 1] + l[_ - 2]) for _ in range(2, n+1)]
- return l[n]
- def fib_faster_last_digit(n):
- return fib_faster(n) % 10
- n = int(input())
- # print(fib_faster(n))
- print(fib_faster_last_digit(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement