#K9891. Check Fibonacci Array
Check Fibonacci Array
Check Fibonacci Array
You are given an array of integers. Your task is to determine whether the array represents a Fibonacci sequence.
A Fibonacci array is defined as follows:
- If N = 0, the array is considered invalid and the answer is
False
. - If N = 1, the array is a Fibonacci array only if its single element is
0
. - If N = 2, the array is a Fibonacci array if the first element is
0
and the second is1
. - If N ≥ 3, then the array must start with
0
and1
, and for every index i ≥ 2 the following condition must hold:</p>$$a_i = a_{i-1} + a_{i-2}.$$
If all these conditions are satisfied, the array is a Fibonacci array; otherwise, it is not.
inputFormat
The input is read from stdin and consists of two lines.
- The first line contains a single integer N, the number of elements in the array.
- The second line contains N space-separated integers representing the array.
outputFormat
Output True if the array is a Fibonacci array; otherwise, output False. The output should be printed to stdout.
## sample6 0 1 1 2 3 5
True