[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 ...
随机推荐
- 第15章 .NET中的反射
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- Java基础---MD5和BASE64
package cn.peter; import sun.misc.BASE64Encoder; import java.io.UnsupportedEncodingException; import ...
- iOS错误总结(三)
1.如果tableView设置为分组的样式(默认是有cell之间的分割线,可以设置颜色),默认有组以及组尾的高度 需要手动在组头组尾的代理方法中进行组高的设置(如果想设置为0,最好写0.01) 2.组 ...
- Java 的replace和replaceAll的使用
(1)replace() 方法通过用 newChar 字符替换字符串中出现的所有 oldChar 字符,并返回替换后的新字符串. public String replace(char oldChar, ...
- XtraReport 添加空行的办法,很详细
这两天为了做报表,研究了一下XtraReport .为了添加空行,想了很多办法.其中如果有分组时,网上给出的办法就会失败.现将经验公布一下,希望各位都能少走弯路. 1.加入自定义函数CreateCel ...
- Oracle 左连接、右连接、全外连接、(+)号作用
分类: Oracle Oracle 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 外连接(Outer ...
- weblogic部署脚本
#!/bin/bash #-- #writen lxh dir_war=/home/weblogic/war dir_app=/servyouapp/weblogic/user_projects/do ...
- jQuery Mobile 列表内容
jQuery Mobile 列表缩略图 对于大于 16x16px 的图像,请在链接中添加 <img> 元素. jQuery Mobile 将自动把图像调整至 80x80px: 实例: &l ...
- Java在处理大数据的时候一些小技巧
Java在处理大数据的时候一些小技巧 发布时间:2013-05-09 00:00:00 来源:中国IT实验室 作者:佚名 关键字:Java 众所周知,java在处理数据量比较大的时候,加载到内存必 ...
- ABAP POPUP函数
POPUP_TO_CONFIRM_LOSS_OF_DATA 弹出一个对话框告知用户有可能丢失数据,询问是否操作继续.POPUP_TO_CONFIRM_STEP 弹出一个对话框询问用户是否操作继续. P ...