Fibonacci Function

Fibonacci Function

Easy Python Functions 15 views
Explanation Complexity

Problem Statement

Read one integer n. Make function fib(n) that returns nth Fibonacci (0-index: fib(0)=0,fib(1)=1). Output fib(n).

Input Format

One integer n.

Output Format

One integer fib(n).

Example

10
55

Constraints

0

Input / Output Format

Input Format
One integer n.
Output Format
One integer fib(n).
Constraints
0

Examples

Input:
10
Output:
55

Example Solution (Public)

Python
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
def fib(x):
  a=0
  b=1
  for _ in range(x):
    a,b=b,a+b
  return a
sys.stdout.write(str(fib(n)))

Official Solution Code

import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
def fib(x):
  a=0
  b=1
  for _ in range(x):
    a,b=b,a+b
  return a
sys.stdout.write(str(fib(n)))
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.