[UCSD白板题] The Last Digit of a Large Fibonacci Number
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的更多相关文章
- [UCSD白板题] Maximize the Value of an Arithmetic Expression
Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
- [UCSD白板题] Take as Much Gold as Possible
Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...
- [UCSD白板题] Primitive Calculator
Problem Introduction You are given a primitive calculator that can perform the following three opera ...
- [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 ...
- [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 ...
- [UCSD白板题] Sorting: 3-Way Partition
Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...
- [UCSD白板题] Majority Element
Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...
随机推荐
- 【Python全栈笔记】03 [模块二] 16-17 Oct 函数
定义一个函数 def function_name(形式参数): 代码块 return 'Value' #如果没有写return,则默认返回None # 一个函数到return这一行就结束执行了,在re ...
- Python SQLAlchemy --2
本文為 Python SQLAlchemy ORM 一系列教學文: 接下來會更深入地探討查詢的使用. 查詢的基本使用法為 session.query(Mapped Class),其後可加 .group ...
- highcharts曲线图
在做项目时,用highcharts做过曲线图,X轴是从后台获取的时间数据,Y轴是从后台获取的Int型数据 1.我的后台数据封装成json格式,数据较多,展示部分数据 2.曲线图的展示 3.前端jsp页 ...
- MongoDB学习:(二)MongoDB简单使用
MongoDB学习:(二)MongoDB简单使用 MongoDB使用: 执行mongodb的操作之前,我们需要运行命令,来进入操作命令界面 >mongo 提示该错误,说明我们系统缺少一个补丁,该 ...
- 编译Hadoop
Apache Hadoop 生态圈软件下载地址:http://archive.apache.org/dist/hadoop/hadoop下载地址 http://archive.apache.org/d ...
- js使用Switch达到切换不同颜色的效果
实现的效果,点击哪个,哪个变颜色,效果如下. 代码如下: <!DOCTYPE html> <html> <head> <meta charset=" ...
- 【WMware】关于VMware服务器虚拟化管理之服务器容量扩充
将服务器物理资源抽象成逻辑资源,让一台服务器变成几台甚至上百台相互隔离的虚拟服务器,我们不再受限于物理上的界限,而是让CPU.内存.磁盘.I/O等硬件变成可以动态管理的“资源池”,从而提高资源的利用率 ...
- 关于实现Extjs动态加载类的方式实现
Extjs4以前的版本没有动态加载类的方式,这样开发程序的时候加载很多的js会导致加载变慢,由于本人一直使用extjs3的版本进行开发,于是简单实现了一个动态加载类的管理器,使用方式与extjs4的方 ...
- c#在主窗体panel 容器内嵌入另一个窗体(子窗体)的实现
主窗体: 子窗体: 把子窗体嵌入到主窗体的panel 右侧中: 代码: { public MainForm() { InitializeComponent(); } private void Clo ...
- HTML5中canvas大小调整
今天用到canvas元素,发现它的大小不是像普通dom元素一样,直接设置css样式可以改变的,它会由自己原本的大小伸缩. 例如, <canvas id='canvas'></canv ...