[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 ...
随机推荐
- 全面的Seo面试题
一.选择题(每题2分,2分×10=20分) 1.白帽SEO诞生日是: A .1997年9月15日 :B .2004年12月13日:C.2005年3月26日:D.2009年6月1日 2.一个做女性服 ...
- 关于Thomas Brinkhoff移动对象生成器的修改
关于地图数据的写出 控制地图路径数据的输出 修改routing.Edge.java 路径写出源码 public void write (EntryWriter out) { out.print(id) ...
- centos7安装数据库
centos7的yum源中貌似没有正常安装MySQL时的mysql-server. 那么就需要从官网下载了. 下面是安装mysql的命令: # wget http://dev.mysql.com/ge ...
- jquery选择器 之 获取父级元素、同级元素、子元素
jquery选择器 之 获取父级元素.同级元素.子元素 一.获取父级元素 1. parent([expr]): 获取指定元素的所有父级元素 <div id="par_div" ...
- C# 获取excel架构并的导入sqlserver的方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Win10切换中英输入法问题
用此方法解决后的效果: Win10系统只剩下"美式键盘"和"搜狗拼音"两种输入法,且默认为美式键盘. 按Ctrl+Shift切换到搜狗拼音,输入完成后,再按Ct ...
- nerual style 执行命令
python neural_style.py --content ./examples/4-content.jpg --styles ./examples/4-faguo-style.jpg --ou ...
- html导入css样式的方法
在html网页中引入css样式表主要有一下四种方法 1.行内引入 <p style="width:100px;height:40px;color:red;"></ ...
- C#调用WebService获取天气信息
概述 本文使用C#开发Winform应用程序,通过调用<WebXml/>(URL:http://www.webxml.com.cn)的WebService服务WeatherWS来获取天气预 ...
- Robot Framework入门学习1 安装部署详解
安装注意: 目前Robot framework-ride不支持python3,安装时请下载python2.7版本. Robot Framework安装时出现了一点小问题,网上没有找到直接的介绍,现将安 ...