Longest Fibonacci

0

0 votes
Medium
Problem

Shubham is a big fan of Fibonacci. He has got a sequence of N integers. Now, he wants to choose some integers from these N integers such that after rearranging these chosen integers, the resulting sequence is a Fibonacci sequence with first 2 terms as some arbitrary integers and remaining integers follow the condition--

  • fi=fi1+fi2

Since, Shubham is not that good at maths, he needs your help in finding the length of longest sequence he can create from given N integers.

Input Format:

First line contains T, number of test cases.

First line of each test case contains N, number of total integers.

Second line contains N integers denoting the sequence.

Output Format:

For each test case, output the required answer in separate lines.

Constraints:

1T5

2N103

1 elements of sequence 109

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

For first case, you can pick sequence as 2, 1, 3, 4. This satisfies the Fibonacci sequence conditions. Hence, answer is 4.

For second case, it isn't possible to make a Fibonacci sequence of length greater than 2.

Editor Image

?