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 \(n\)th Fibonacci number \(F_n\).

Input Format.The input consists of a single integer \(n\).

Constraints.\(0 \leq n \leq 45\).

Output Format.Output \(F_n\).

Sample 1.
Input:

3

Output

2

Sample 2.
Input:

10

Output:

55

Solution

# Uses python3
def calc_fib(n):
    x,y = 0,1
    while n > 0:
        x,y,n = y,x+y,n-1
    return x
n = int(input())
print(calc_fib(n))

[UCSD白板题 ]Small Fibonacci Number的更多相关文章

  1. [UCSD白板题] Huge Fibonacci Number modulo m

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  2. [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_ ...

  3. [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 ...

  4. 【LeetCode每天一题】Fibonacci Number(斐波那契数列)

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  5. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  6. [UCSD白板题] Take as Much Gold as Possible

    Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...

  7. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  8. [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 ...

  9. [UCSD白板题] Pairwise Distinct Summands

    Problem Introduction This is an example of a problem where a subproblem of the corresponding greedy ...

随机推荐

  1. sublime中侧边栏字体大小的设置

    sublime这个编辑器相当强大,但是它的侧边栏字体实在是太小了,实在是反人类的设计,幸好它给了我们修改的机会 第一步:下载PackageResourceViewer插件,通过PackageContr ...

  2. c++继承概念

    蠢了3年了,在找工作的今天明白了何为继承……呵呵呵…… 3种继承方式:public.protected.private. 注意几点: 1.继承只能继承基类的public和protected成员 2.3 ...

  3. 从西直门立交桥谈IT架构与重构(干货)

    2015年8月13日 PM 20:00 Neeke君从一个战场奔赴至另一个战场,回到办公室,打开电脑,登陆微信,精彩的的微社群分享马上就要开始了! 大家好,我是Neeke,中文名高驰涛,PHP开发组成 ...

  4. http2协议翻译(转)

    超文本传输协议版本 2 IETF HTTP2草案(draft-ietf-httpbis-http2-13) 摘要 本规范描述了一种优化的超文本传输协议(HTTP).HTTP/2通过引进报头字段压缩以及 ...

  5. android中string.xml中%1$s、%1$d等的用法

    今天在研究前辈写的代码的时候,突然发现string里面出现了<stringname="item_recent_photo">最近拍摄%1$s</string> ...

  6. [原创][LaTex]汇总博文

    0. 简介 为了查找方便,当当当当,灵机一动的设计了这个博文,有了他就能快速的查找一些该话题相关方面的一些博文了,不管是原创.转载.整理,只要是属于我自己整理的LaTex知识,应该都可以在这里找到的. ...

  7. oracle函数应用

    ----Oracle中的函数 oracle中函数的分类: --第一种:日期函数 --第二种: 字符函数 --第三种: 数学函数 --第四种: 转换函数 --第五种: 分析函数 ------------ ...

  8. ios UILabel在storyBoard或xib中如何在每行文字不显示完就换行

    大家知道怎么用代码让label中的文字换行,只需要 label.numberOfLines = 0; label.text = @"这是第一行啦啦啦啦,\n这是第二行啦啦,\n这是第三行&q ...

  9. 编辑器Ultraedit快捷键

    编辑器Ultraedit快捷键说到编辑器的快捷键,VIM是无与伦比的.要反对,也得是带脚踏板的EmaCS.UE还是有差距的,很大差距.注意:VIM是开源.免费的,而UE则需要注册.UE是Windows ...

  10. Fedora 21 64位系统安装WPS教程

    WPS的Linux版本的出现简直是Linux党的福音,Ubuntu上的WPS安装非常简单,但是在Fedora上却有点小麻烦.主要是库的依赖问题.下面记录一下Fedora 21的64位版安装WPS的完整 ...