Asked inMicrosoft Corporation,SWE Intern

Nth Element of Modified Fibonacci Series

Given two integers X and Y as the first two elements of a series, and another integer N, find the Nth number of the series utilizing the Fibonacci rule: f(x) = f(x - 1) + f(x - 2).

Note: Return the answer modulo 10^9 + 7 as it may be very large.

Note:

The series is 1-based indexed.

Input:

The first line contains an integer T representing the number of test cases. Each test case consists of a single line with three space-separated integers X, Y, and N. X and Y are the first and second elements of the series, while N is the position of the number to find.

Output:

For each test case, output a single integer representing the Nth number of the series. Each output should be on a new line.

Example:

Input:
T = 2
X = 2, Y = 3, N = 3
X = 1, Y = 1, N = 5
Output:
5
3

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 10^18
  • -10^6 ≤ X, Y ≤ 10^6
  • Time limit: 1 sec.

Note:

You are not required to print anything; it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Microsoft Corporation SWE Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter