#K6191. Custom Fibonacci-Like Sequence
Custom Fibonacci-Like Sequence
Custom Fibonacci-Like Sequence
You are given three integers n
, a
, and b
. Your task is to compute the n-th term of a Fibonacci-like sequence defined as follows:
$$F(1)=a, \quad F(2)=b, \quad F(n)=F(n-1)+F(n-2) \quad \text{for } n>2.$$
For example, given n = 5
, a = 4
, and b = 7
, the sequence is: 4, 7, 11, 18, 29, so the output should be 29
.
inputFormat
The input consists of a single line containing three space-separated integers: n
, a
, and b
, where n
denotes the term to compute, and a
and b
are the first two terms of the sequence respectively.
outputFormat
Output a single integer which is the n-th term of the Fibonacci-like sequence.
## sample1 4 7
4