Geeksforgeeks

Error

Given 4 integers A, B, C and N, find the value of F(N) such that

F(1) = A + B

F(2) = B + C

F(N) = F(N-1) - F(N-2), for N > 2.

**Example 1:**

**Input:** N = 2, A = 2, B = 3, C = 4
**Output:** 7
**Explaination:** F(2) = B+C = 3+4 = 7

**Example 2:**

**Input:** N = 3, A = 2, B = 3, C = 4
**Output:** 2
**Explaination:** F(3) = F(2)- F(1) = 7-5 = 2

**Your Task:**

You do not need to read input or print anything. Your task is to complete the function **modifiedFib()** which takes the values N, A, B and C as input parameters and returns F(N). Since F(N) modulo (10^{9}+7).

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

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

**Constraints:**

1 ≤ N ≤ 10^{12}

1 ≤ A, B, C ≤ 10^{9}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

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?

YesLoading...

Modified Fibonacci

...