Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Lucas Number
Easy Accuracy: 35.38% Submissions: 99 Points: 2

A Lucas Number is a number which is represented by the following recurrence
Ln = Ln-1 + Ln-2 for n>1
L0 = 2
L1 = 1

Given a number N, find the Nth lucas number.

Note: Since the output may be very large calculate the answer modulus 10^9+7.


Example 1:

Input:
N = 5
Output: 11
Explanation: L3 + L4 = L5
L3 = 4 and L4 = 7


​Example 2:

Input: 
N = 7
Output: 29
Explanation: L5 + L6 = L7
L5 = 11 and L6 = 18


Your Task:
You don't need to read input or print anything. Your task is to complete the function lucas() which takes integer N  as input parameter and return Nth
  Lucas number.


Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)


Constraints:
1 <= N <= 106

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Lucas Number

Output Window