[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 ...
随机推荐
- SQL Server 2008R2数据库文件导入到SQL Server 2008数据库中
最近,电脑重装系统之后,安装了SQL Server 2008.附加数据库文件的时候,发现无法附加,提示版本不对.想起来,原来的数据库版本是SQL Server 2008R2.低版本的数据库管理工具无法 ...
- Maven Archetype
1. 从project创建archetype 在项目根目录下,运行 mvn archetype:create-from-project 创建的archetype工程在app_folder/target ...
- Android Dex文件格式(二)
第三块: 数据区 索引区中的最终数据偏移以及文件头中描述的map_off偏移都指向数据区, 还包括了即将要解析的class_def_item, 这个结构非常重要,下面就开始解析 c ...
- LINQ to XML 编程基础
1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...
- linux 程序管理与SElinux
此文涉及的命令:&.jobs.fg.bg.kill.nohup.ps.top.pstree.free.uname.uptime.netstat.dmesg.vmstat.fuser.lsof. ...
- java中的条件语句(if、if...else、多重if、嵌套if)
Java条件语句之 if 生活中,我们经常需要先做判断,然后才决定是否要做某件事情.例如,如果考试成绩大于 90 分,则奖励一个 IPHONE 5S .对于这种"需要先判断条件,条件满足后才 ...
- 无法在Web服务器上启动调试,已附加了一个调试器
运行环境:开发环境:Windows7旗舰版64bit.VisualStudio2008 With SP1.ArcEngine10.0.NetFrameWork4.0.IIS7和C#开发语言. 问题描述 ...
- MVC中获取模型属性的Range和StringLength验证特性设置
MVC中的客户端及服务端模型验证信息都以ModelMetadata类型作为承载,在获得属性的ModelMetadata之后(还不知道怎么获取ModelMetadata的童鞋请自行恶补),我们可以轻松得 ...
- android 使用LinearGradient进行字体渐变的效果
有这么一种效果,一串字符有一束白光从字体上面闪光的效果.如下图显示: 就像上面的显示效果一样一束白光闪过,这种效果主要还是使用了LinearGradient类来进行的 LinearGradient也称 ...
- nginx+uwsgi<django web环境的搭建>
1.sudo pip install uwsgi 2.sudo apt install nginx 3.sudo /etc/init.d/nginx start 4.netstat -tpnl 5./ ...