No.954 Result
タグ : / 解いたユーザー数 137
作問者 :
alpha_virginis
Problem Statement
You are given 5 lines of input data. Output the maximum $n(1 \leq n \leq 5)$ such that the lines up to the $n$-th line counted from the bottom, read from the bottom, form a part of the Fibonacci sequence (1,1,2,3,…) that is consecutive and in ascending order. If no $n$ satisfies the condition, output 0.
See the sample inputs for details.
Input
$a_1$ $a_2$ $a_3$ $a_4$ $a_5$
$0 \leq a_i \leq 10^{15} (1 \leq i \leq 5)$
Output
Output the maximum $n(1 \leq n \leq 5)$ such that the lines up to the $n$-th line counted from the bottom, read from the bottom, form a part of the Fibonacci sequence (1,1,2,3,…) that is consecutive and in ascending order. If no $n$ satisfies the condition, output 0. (See the sample cases for details.)
Print a newline at the end.
Sample
Sample 1
Input
543 1 1 2 3
Output
1
Read from the top, there is a consecutive part of the Fibonacci sequence, {1,1,2,3}, but read from the bottom it is {3,2,1,1}, which is not in ascending order, so 4 is not the answer. Similarly, {3, 2, 1} and {3, 2} are not in ascending order, so 3 and 2 are not the answer either.
{3} satisfies the condition, so output 1.
Corrected on 2019/12/17 00:39: fixed the part that previously read "Similarly, {3, 2, 1},{2, 1}".
Sample 2
Input
458 10 3 2 1
Output
3
{1, 2, 3} is a part of the Fibonacci sequence {1, 1, 2, 3, ...}.
Sample 3
Input
650 3 2 1 1
Output
4
Up to the 4th line counted from the bottom, the lines are in ascending order and form a consecutive part of the Fibonacci sequence.
Sample 4
Input
452 7 5 3 2
Output
3
{2,3,5,8} is a consecutive part of the Fibonacci sequence, but
{2,3,5,7} is not, so output 3.
Sample 5
Input
821 0 0 0 9
Output
0
{9} is not a consecutive part of the Fibonacci sequence, so output 0.
Sample 6
Input
233 144 89 55 34
Output
5
Sample 7
Input
72723460248140 44945570212853 27777890035288 17167680177565 10610209857723
Output
4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。