#K50752. Magical Number Generation
Magical Number Generation
Magical Number Generation
You are given two integers: M and D. The task is to compute the magical number produced on the D-th day using the following recurrence:
\( f(0) = M \), \( f(1) = M \) and for \( D \ge 2 \), \( f(D) = f(D-1) + f(D-2) \).
This recurrence is analogous to the Fibonacci sequence, but both the first and second values are initialized with M (which can be negative or zero). Write a program that reads the two integers from stdin and prints the magical number on stdout in one line.
Note on Input/Output: The input consists of a single line with two space-separated integers, and the output is a single integer representing the magical number on the D-th day.
inputFormat
The input is provided via standard input and consists of a single line with two space-separated integers:
- M: the initial value of the sequence.
- D: the day number.
outputFormat
The output should be printed to standard output and is a single integer representing the magical number on the D-th day.
If D is less than 2, the output is simply M. Otherwise, for D \(\ge\) 2, compute the number using the recurrence
\[ f(D)=f(D-1)+f(D-2). \]## sample3 0
3