{"problem":{"name":"C. Tennis Championship","description":{"content":"Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be _n_ players participating, and the tournament will follow knockout rules fro","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF735C"},"statements":[{"statement_type":"Markdown","content":"Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be _n_ players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.\n\nOrganizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played **differs by no more than one** from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.\n\nTournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.\n\n## Input\n\nThe only line of the input contains a single integer _n_ (2 ≤ _n_ ≤ 1018) — the number of players to participate in the tournament.\n\n## Output\n\nPrint the maximum number of games in which the winner of the tournament can take part.\n\n[samples]\n\n## Note\n\nIn all samples we consider that player number 1 is the winner.\n\nIn the first sample, there would be only one game so the answer is 1.\n\nIn the second sample, player 1 can consequently beat players 2 and 3.\n\nIn the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"著名的巴西城市里约热内卢举办了一场网球锦标赛，奥斯塔普·本德不想错过这一赛事。将有 #cf_span[n] 名选手参赛，锦标赛从第一场比赛开始就采用淘汰制，这意味着一旦某位选手输掉一场比赛，他将立即被淘汰。\n\n组织者仍在安排赛程（即比赛的顺序和对阵安排），但他们已经固定了一条规则：两名选手只有在他们已进行的比赛场数之差不超过一的情况下才能相互对阵。当然，两名选手都必须赢得所有之前的比赛才能继续参赛。\n\n锦标赛尚未开始，观众有些无聊。奥斯塔普决定找出冠军最多能参加多少场比赛（假设使用上述规则）。然而，他很可能无法在没有你帮助的情况下解决这个问题。\n\n输入仅包含一行，一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 1018]）——参赛选手的数量。\n\n请输出冠军最多能参加的比赛场数。\n\n在所有样例中，我们假设选手编号为 #cf_span[1] 的是冠军。\n\n在第一个样例中，仅有一场比赛，因此答案为 #cf_span[1]。\n\n在第二个样例中，选手 #cf_span[1] 可以依次击败选手 #cf_span[2] 和 #cf_span[3]。\n\n在第三个样例中，选手 #cf_span[1] 无法与每位其他选手比赛，因为在他击败了选手 #cf_span[2] 和 #cf_span[3] 之后，他无法与选手 #cf_span[4] 对阵，因为选手 #cf_span[4] 尚未进行任何比赛，而选手 #cf_span[1] 已经打了 #cf_span[2] 场。因此，答案是 #cf_span[2]，为了实现这一点，我们安排配对 #cf_span[(1, 2)] 和 #cf_span[(3, 4)]，然后让胜者对决。\n\n## Input\n\n输入仅包含一行，一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 1018]）——参赛选手的数量。\n\n## Output\n\n请输出冠军最多能参加的比赛场数。\n\n[samples]\n\n## Note\n\n在所有样例中，我们假设选手编号为 #cf_span[1] 的是冠军。在第一个样例中，仅有一场比赛，因此答案为 #cf_span[1]。在第二个样例中，选手 #cf_span[1] 可以依次击败选手 #cf_span[2] 和 #cf_span[3]。在第三个样例中，选手 #cf_span[1] 无法与每位其他选手比赛，因为在他击败了选手 #cf_span[2] 和 #cf_span[3] 之后，他无法与选手 #cf_span[4] 对阵，因为选手 #cf_span[4] 尚未进行任何比赛，而选手 #cf_span[1] 已经打了 #cf_span[2] 场。因此，答案是 #cf_span[2]，为了实现这一点，我们安排配对 #cf_span[(1, 2)] 和 #cf_span[(3, 4)]，然后让胜者对决。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"Let $ n \\in \\mathbb{Z} $ with $ 2 \\leq n \\leq 10^{18} $ be the number of players.\n\nDefine $ f(n) $ as the maximum number of games the winner can play under the constraint that two players may only compete if the number of games each has already played differs by at most one.\n\n**Objective**:  \nCompute $ f(n) $, where $ f(n) $ satisfies the recurrence:  \n$$\nf(1) = 0, \\quad f(2) = 1\n$$\n$$\nf(n) = \\max_{\\substack{a + b = n \\\\ |f(a) - f(b)| \\leq 1}} \\left(1 + \\max(f(a), f(b))\\right)\n$$\n\nEquivalently, $ f(n) $ is the largest integer $ k $ such that the $ k $-th Fibonacci number $ F_{k+2} \\leq n $, i.e.,  \n$$\nf(n) = \\max \\{ k \\in \\mathbb{N} \\mid F_{k+2} \\leq n \\}\n$$  \nwhere $ F_1 = 1, F_2 = 1, F_3 = 2, F_4 = 3, \\dots $ is the Fibonacci sequence.\n\n**Output**: $ f(n) $","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF735C","tags":["combinatorics","constructive algorithms","greedy","math"],"sample_group":[["2","1"],["3","2"],["4","2"],["10","4"]],"created_at":"2026-03-03 11:00:39"}}