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. Android(Intent 学习)

    Intent 是一个消息传递对象,Intent可以通过多种方式促进组件之间的通信,基本的三种用例: 启动Acitivity: Activity表示应用中的一个屏幕,通过将Intent传递给startA ...

  2. oracle 身份证校验函数

    1.正则表达式写法: CREATE OR REPLACE FUNCTION Func_checkidcard (p_idcard IN VARCHAR2) RETURN INT IS v_regstr ...

  3. StringUtils方法全集

    org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的( ...

  4. android虚拟机

    参考:http://baike.baidu.com/link?url=06bC3y5DSQ7DQ_QbEr6hTfMNpmg2f-39w6FpU69xxkbNoJ5OR4N9xCKoMwMMGTZfF ...

  5. 四、解决MyEclipse控制台输出中文乱码的问题

    问题描述:       在Java程序中,在MyEclipse开发环境下,通过标准输入输入中文,并把输入的中文信息从标准输出显示出来,这时中文出现乱码情况.解决方法:解决方法需要两个步骤(本文测试环境 ...

  6. oracle字符查出一位

    select cast('a' as varchar2(64)) from dual;

  7. CSS 图片倾斜的制作

    <style> #zhong{ height:600px; width:1350px; position:relative; z-index:2} .znei{ height:60px; ...

  8. aspx页面,中文乱码解决方案

    由于文件编码方式编码方式不统一出现样式中文乱码解决方案: 今天碰到的问题:页面字体样式设置的'微软雅黑',可页面没引用.我调试看到样式出现中文乱码了 这种问题,就需要转换文件的编码方式,如下两步即可解 ...

  9. .NET程序优化

    一.数据库操作 1. 用完马上关闭数据库连接 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证, 比较耗费服务器资 源.ASP.NET 中提供了连 ...

  10. 选择c3p0作为连接池

    <hibernate-configuration>     <session-factory>         <property name="dialect& ...