No.1268 Fruit Rush 2
Problem Statement
The Fibonacci sequence $\{F_i\}$ is the sequence defined by $F_0 = F_1 = 1, \ F_{i+2} = F_{i+1} + F_i \ (i \geq 0)$. A number contained in the Fibonacci sequence is called a Fibonacci number.
There are $N$ fruits, and the freshness of the $i$-th fruit is $F_{A_i}$.
Here, $A_i$ is a positive integer; in particular, $A_i \neq 0$.
Also, if $i \neq j$, then $A_i \neq A_j$.
Hanyu will choose at least $1$ and at most $N$ of these fruits to make mixed juice.
Since Hanyu loves Fibonacci numbers, she wants to choose the fruits so that the sum of the freshness of the chosen fruits is again a Fibonacci number.
Find the total number of such ways to choose the fruits. (It can be proved that the answer does not exceed $10^{18}$ under these constraints.)
Two ways of choosing fruits are considered different if there exists a fruit that is chosen in one but not chosen in the other.
Input
$N$ $A_1\ A_2\ \dots \ A_N$
- All inputs are integers.
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq A_i \leq 10^{18}$
- If $i \neq j$, then $A_i \neq A_j$.
Output
Output the total number of ways to choose the fruits so that the sum of their freshness is a Fibonacci number.
Sample
Sample 1
Input
3
3 4 5
Output
5
The freshness values of the fruits are $F_3=3,F_4=5,F_5=8$, and the following 5 ways satisfy the condition. (Typo corrected on 2020/10/23 23:43.)
- $3 = F_3$
- $5 = F_4$
- $8 = F_5$
- $3+5 = F_5$
- $5+8 = F_6$
Sample 2
Input
4
1 10 100 1000
Output
4
Sample 3
Input
8
3 1 4 15 9 2 6 5
Output
17
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
stoq
hanyu