AI robot highest level

AI robot highest level

Title Description

In the game world of little juju, there are n number of AI robots.
They can be mutual between PK, winner survive and level up, loser eliminated directly.
AI must overcome the high level of low-level AI, must win and one loss with a level of AI PK results, and require each grade level gap of at most 1.
The beginning of AI robots are all 0, two small juju can specify any AI robots perform PK.
Small juju would like to know, AI Tournament conducted in accordance with this rule, the highest level AI robot can produce as much class.

Enter a description

A positive integer n, $ 2 <= n <= 10 ^ {18} $, represents the number of robot AI

Output Description

At the end of the game, the highest level attainable level of AI robot

Examples

Input: 2; Output: 1
Input: 4; Output: 2
Input: 72; Output: 8

Resolve

The beginning of this topic seems to have no ideas, then take a look at the case of the minimum required in front of the highest level.

First look at the highest level would be under what circumstances, to use the example of 72 as an example:

If 220 for PK, will give Level 1 AI robot 36, and then twenty-two PK, 18 can be obtained Level 2 AI robot.

If let the part 0 for PK, and then rose to the robot and the remaining 1 AI 0 robot PK, where just 72 divisible by 3, the first means PK, to give 24 Level 1 AI 24 0 robots and AI robot, let PK second class 1 AI robots and AI robot PK 0, you can get 24 level 2 AI robot.

It can be seen, will produce more sibling AI robot when high and low level, which means it will also get the highest level of AI robots.

In this way, we let the number from a few low-level AI robot required a minimum of 0 AI robot is the number:

0 robot \ (n_0 \) : 1

Level 1 robot \ (n_1 \) : 2

Level 2 Robot \ (and n_2 \) : \ (N - 0 + + 2. 1 of n_1 = \)

Level 3 robot \ (n_3 \) : \ (of n_1 and n_2 = + 2 + = 2. 1. 1 + 2 * 2 + \)

Level 4 robot \ (n_4 \) : \ (= n_3 and n_2 +. 1. 1 + 2 + 2 + 2 =. 1 * * * 2 + 2. 3 \)

5 Robot \ (n_5 \) : \ (n_4 + n_3 * =. 3. 1. 5 * 2 + \)

6 Robot \ (n_6 \) : \ (n_4 n_5 + + =. 5. 1 * 2 *. 8 \)

7 Robot \ (n_7 \) : \ (n_5 n_6 + + =. 8. 1 * 2 * 13 is \)

8 Robot \ (n_8 \) : \ (n_6 n_7 + =. 1 + 2 * * 13 is 21 is \)

9 Robot \ (n_9 \) : \ (n_7 n_8 + =. 1 + 2 * * 21 is 34 is \)

..................................

It can be seen, where the coefficients satisfy the Fibonacci number, assuming two adjacent Fibonacci numbers of Number of \ (A, B (A <B) \) , then, \ (N_x. 1 = A * 2 * b + \) .

Since the input 2 minimum, visibility Fibonacci number starting from 0, 1 is the highest level at this time. Iterative a Fibonacci sequence of Number of coefficients, the highest level plus 1, if the coefficient calculated at the \ (N_x \) just to meet the input value, the highest level at this time is \ (X \) , if \ ( {X}. 1-of N_ <n-<{X} of N_ \) , then the time for the highest level \ (. 1-X \) .

Accordingly, it is possible to compile the following procedure.

def ai_pk_grade(total_num):
    a, b = 0, 1
    grade = 1
    if total_num <= 1:
        return 0

    while True:
        required_num = a * 1 + b * 2
        if required_num > total_num:
            return grade - 1
        elif required_num == total_num:
            return grade
        else:
            a, b = b, a+b
            grade = grade + 1

while True:
    num = int(input())
    print(ai_pk_grade(num))

Guess you like

Origin www.cnblogs.com/fenghualong/p/11568259.html