[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 ...
随机推荐
- js常用正则
var sTest="xxxkdsj234dogdog1234xx"var reTest1=/(dog){2}/var reTest2 = /(?:dog){2}/;console ...
- Java Sha1 加密算法
//下面四个import放在类名前面 包名后面 //import java.io.UnsupportedEncodingException; //import java.security.Messag ...
- ffmpeg总结整理
ffmpeg总结整理参考链接: http://www.cnblogs.com/youngt/p/5754415.html
- 从SQL下载大量数据到Excel
之前不知设计原理,发生了大量数据(超过100w行)直接从数据库读取加载到网页中,直接导致内存溢出. Rediculous! 所以,现在改为分页查询到页面中. 由于其有全局逻辑,故折中每次加载1w条数据 ...
- SQL中CONVERT日期不同格式的转换用法
SQL中CONVERT日期不同格式的转换用法 格式: CONVERT(data_type,expression[,style]) 说明:此样式一般在时间类型(datetime,smalldatetim ...
- 40多个纯CSS绘制的图形
本文由码农网 – 陈少华原创,转载请看清文末的转载要求. 今天在国外的网站上看到了很多看似简单却又非常强大的纯CSS绘制的图形,里面有最简单的矩形.圆形和三角形,也有各种常见的多边形,甚至是阴阳太极和 ...
- python splinter
from splinter.browser import Browser with Browser() as b: for url,name in web: b.visit(url) b.fill(' ...
- Yii2 return redirect()
理想情况下是: return $this->redirect($url);立马跳转, 而不执行后续代码; 但是在init方法中是无效的,需要加上Yii::$app->end();即可终止后 ...
- tp框架简易导出数据库
类库,将以下文件放入vendor文件夹中,命名空间vendor,使用think下的model类 <?php /** * 描述:基于ThinkPHP框架的Mysql数据库导出类 * 日期:2012 ...
- DLL强名称引用问题
为没有源码的DLL文件添加强名称 如果项目中引用了其他没有源码的dll文件,并且此dll文件是没有强名称的程序集,则编译时会出现类似 "Assembly generation failed ...