Solve Linear Recurrence

Solve Linear Recurrence

Hard Computer Mathematics Recurrences 28 views
Explanation Complexity

Problem Statement

Given f0,f1 and f(n)=f(n-1)+2f(n-2), compute f(n).

Input Format

f0 f1 n.

Output Format

One integer.

Example

0 1 5
21

Constraints

0

Input / Output Format

Input Format
f0 f1 n.
Output Format
One integer.
Constraints
0

Examples

Input:
0 1 5
Output:
21

Example Solution (Public)

Computer Mathematics
Iterate from 2..n using recurrence, store last two values.

Official Solution Code

Iterate from 2..n using recurrence, store last two values.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.