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...
Optum Global Solutions Software Engineer interview questions & answers
A Software Engineer was asked 3mo agoQ. What types of joins are you familiar with?
A Software Engineer was asked 4mo agoQ. What is the process for implementing a linked list?
A Software Engineer was asked 4mo agoQ. What are the features of Java 8?
Popular interview questions of Software Engineer
A Software Engineer was asked 3mo agoQ1. What types of joins are you familiar with?
A Software Engineer was asked 4mo agoQ2. What is the process for implementing a linked list?
A Software Engineer was asked 4mo agoQ3. What are the features of Java 8?
Top HR questions asked in Optum Global Solutions Software Engineer
A Software Engineer was asked 4mo agoQ1. Rate your proficiency in the technologies listed in your skills.
A Software Engineer was asked Q2. Why do you want to join?
A Software Engineer was asked Q3. Explain your projects and work.
>
Optum Global Solutions Software Engineer Interview 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

