#P12036. Earning Mora: Ningguang's Wealth Strategy

    ID: 14141 Type: Default 1000ms 256MiB

Earning Mora: Ningguang's Wealth Strategy

Earning Mora: Ningguang's Wealth Strategy

Ningguang, the esteemed Tianquan of Liyue, has discovered a novel method to earn Mora. If she earns \( p \) Mora on the first day and \( p+1 \) Mora on the second day, then from the third day onward her daily earnings become the sum of the previous two days. In other words, the sequence \( f(n) \) is defined as:

\[ \begin{aligned} f(1)&=p,\\ f(2)&=p+1,\\ f(n)&=f(n-1)+f(n-2) \quad \text{for } n \ge 3. \end{aligned} \]

This can be rewritten using Fibonacci numbers \( F(n) \) (with \( F(0)=0 \) and \( F(1)=1 \)) as:

\[ f(n)=F(n)\,p+F(n-1). \]

If you are given that on day \( a \) the earned Mora is \( x \), determine the amount of Mora earned on day \( b \).

inputFormat

The input consists of three space-separated integers:

  • \( a \) — the day for which the earned Mora \( x \) is known,
  • \( x \) — the number of Mora earned on day \( a \),
  • \( b \) — the day for which you need to compute the earned Mora.

You may assume the input values are such that \( p \) is an integer.

outputFormat

Output a single integer representing the number of Mora earned on day \( b \).

sample

1 5 2
6