Ways to Reach N
Python
Medium
4 views
Problem Description
You are at step 0 and want to reach step n. Each move you can go +1 or +2. Output number of ways modulo 1000000007.
Input Format
One integer n.
Output Format
One integer ways.
Official Solution
import sys
MOD=1000000007
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
if n==0:
sys.stdout.write('1')
elif n==1:
sys.stdout.write('1')
else:
a=1
b=1
for _ in range(2,n+1):
a,b=b,(a+b)%MOD
sys.stdout.write(str(b))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!