Geeksforgeeks

Error

×

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 | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@anishrajan | 505 |

@thanosagain | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

A Lucas Number is a number which is represented by the following recurrence

L_{n} = L_{n-1} + L_{n-2} for** n>1**

L_{0} = 2

L_{1} = 1

Given a number **N,** find the N** ^{th}** 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**: L_{3} + L_{4} = L_{5
}L_{3 }= 4 and L_{4} = 7

â€‹**Example 2:**

Input: N = 7Output:29Explanation: L_{5}+ L_{6}= L_{7}L_{5}_{ }= 11 and L_{6}= 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 N^{th} Lucas number.

**Expected Time Complexity: **O(N)

**Expected Auxiliary Space: **O(1)

**Constraints:**

1 <= N <= 10^{6}

Login to report an issue on this page.

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

Yes
Lucas Number

...