#C284. Fibonacci Functions Challenge

    ID: 46200 Type: Default 1000ms 256MiB

Fibonacci Functions Challenge

Fibonacci Functions Challenge

This problem requires you to implement three functionalities related to the Fibonacci sequence. In this challenge, you will process multiple queries where each query is of one of the following types:

  • Type 1: Given an integer n (with 1-based indexing), compute the nth Fibonacci number. The Fibonacci sequence is defined as: \(F(1)=0, F(2)=1, F(n)=F(n-1)+F(n-2)\) for \(n > 2\).
  • Type 2: Given an integer, check whether it is a Fibonacci number. Output True if it is, otherwise output False.
  • Type 3: Given an integer m, output the first m Fibonacci numbers (starting from \(F(1)=0\)) separated by a single space.

The input starts with an integer \(Q\) representing the number of queries. Each of the following \(Q\) lines contains a query in one of the following formats:

  • For type 1: 1 n
  • For type 2: 2 number
  • For type 3: 3 m

You must read the input from standard input (stdin) and write the results to standard output (stdout). Each query result should be printed on a new line.

inputFormat

The first line of input contains an integer \(Q\), the number of queries. The next \(Q\) lines each contain a query in one of the following formats:

  • 1 n: Compute the nth Fibonacci number.
  • 2 number: Check if number is a Fibonacci number (output either True or False).
  • 3 m: Output the first m Fibonacci numbers separated by spaces.

outputFormat

For each query, output the result on a new line. For type 1 and type 2 queries, output a single value. For type 3 queries, output a space-separated sequence of numbers.

## sample
1
1 10
34

</p>