#K9891. Check Fibonacci Array

    ID: 39130 Type: Default 1000ms 256MiB

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 is 1.
  • If N ≥ 3, then the array must start with 0 and 1, 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.

    1. The first line contains a single integer N, the number of elements in the array.
    2. 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.

    ## sample
    6
    0 1 1 2 3 5
    True