Problem Introduction

The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_{i-1}+F_{i-2}\) for $ i \geq 2$.

Problem Description

Task.Given an integer \(n\),find the last digit of the \(n\)th Fibonacci number \(F_n\)(that is , \(F_n \ mod \ 10\)).

Input Format.The input consists of a single integer \(n\).

Constraints.\(0 \leq n \leq 10^7\).

Output Format.Output the last digit of \(F_n\).

Sample 1.
Input:

3

Output:

2

Sample 2.
Input:

327305

Output:

5

Solution

# Uses python3
import sys

def get_fibonacci_last_digit(n):
    x,y = 0,1
    while n > 0:
        x,y,n = y%10,(x+y)%10,n-1
    return x

if __name__ == '__main__':
    input = sys.stdin.read()
    n = int(input)
    print(get_fibonacci_last_digit(n))

[UCSD白板题] The Last Digit of a Large Fibonacci Number的更多相关文章

  1. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  2. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  3. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  4. [UCSD白板题] Take as Much Gold as Possible

    Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...

  5. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  6. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  7. [UCSD白板题] Number of Inversions

    Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...

  8. [UCSD白板题] Sorting: 3-Way Partition

    Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...

  9. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

随机推荐

  1. 深入理解 NodeList

    在web前端编程中,我们通常会通过document.getElementsByTagName的方法取出一组相同标签的dom元素,比如: var list = document.getElementsB ...

  2. oracle 队列

    Oracle 高级队列(AQ) 适用对象:初步了解oracle高级队列人群 注意事项: 序号 注意事项 1 JMS监听部分可参考官方文档: http://docs.oracle.com/cd/e128 ...

  3. linux命令(1):ls命令

    ls命令是linux下最常用的命令. ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单,如果ls指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看lin ...

  4. 我的Git使用-资料查询,名博笔记

    1.首先您要知道什么是GIT 2.然后对其GIT的历史有所了解(吹牛b的时候用得着,如果还不知道 linux 脱袜子 Linus Torvalds  o(︶︿︶)o ) Git 常用资料查询站点. 官 ...

  5. 【随笔】从gitHub上获取源码

    有时候,需要从gitHub上获取源码,下面介绍几个方法: 1.获取链接: 打开gitHub代码库的页面,能在右边看到这个: 点击红圈里的标记,该链接就会复制下来. 然后,如果安装了小乌龟(Tortoi ...

  6. django 1.8 TEMPLE_DIR和STATICFILES_DIRS配置

    django 1.6后settings.py文件中没有了TEMPLATE_DIRS模板目录和STATICFILES_DIRS静态访问目录,需要手动添加,最近也遇到这个问题,把解决办法说一下 1.环境 ...

  7. MVC随笔之基础数据维护(MVC4+Boostrap)

    一般的管理系统都会设定一些basedata,方便用户交互,以前一直用webform开发,各种粘贴复制已经感觉没啥新意了(我是老油条...),现在公司开始接手第一个MVC项目,所以今天写下MVC中的ba ...

  8. Security.website-that-focus-on-mobile-app-security

    Mobile App Security 1. DATA THEOREM LAB https://datatheorem.github.io/ Data Theorem's technical blog ...

  9. CentOS 6.5升级Python和安装IPython

    <转自:http://www.noanylove.com/2014/10/centos-6-5-sheng-ji-python-he-an-zhuang-ipython/>自己常用.以做备 ...

  10. js如何找到方法在哪个js文件

    在Console窗口中输入var f = methodA.prototype.constructor;console.log(f); 网络搜索到的方法.