
Asked in MAQ Software
Nth Element Of Modified Fibonacci Series
Given two integers X
and Y
as the first two numbers of a series, and an integer N
, determine the Nth element of the series following the Fibonacci rule: f(x) = f(x - 1) + f(x - 2)
.
The result may be very large, so return the answer modulo 10^9 + 7
.
Example:
Input:
X = 1, Y = 1, N = 5
Output:
5
Explanation:
The series starts as 1, 1, 2, 3, 5...
Constraints:
1 <= T <= 100
1 <= N <= 10^{18}
-10^{6} <= X, Y <= 10^{6}
- Time limit: 1 sec.
Input:
The first line contains an integer T denoting the number of test cases. For each test case, there is a line with three space-separated integers ‘X’, ‘Y’, and ‘N’ where ‘X’ and ‘Y’ are the initial numbers of the series, and ‘N’ is the position in the series.
Output:
For each test case, print the Nth number of the series, each in a new line.
Note:
The series is 1-based indexed, and you don't need to print anything manually; you need to implement the function to obtain the answer.

AnswerBot
4mo
Calculate the Nth element of a modified Fibonacci series given the first two numbers and N, with the result modulo 10^9 + 7.
Implement a function to calculate the Nth element of the series using the Fi...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at MAQ Software
Q. Given an array of integers nums and an integer target, return indices of the two...read more
Q. Write an SQL query to find the top 2 candidates.
Q. Minimum Travel Time Problem Statement Mr. X plans to explore Ninja Land, which c...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for MAQ Software Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

