The long night P12494


Statement
 

pdf   zip

html
George R.R. Martin is a masterful writer, but he writes very slowly. The TV series Game of Thrones initially followed his books, but during the last season the TV script writers couldn’t follow George’s story, because he still hadn’t finished writing it! This resulted in a universally disappointing season, which has angered many fans.

The TV series took its downturn in an unrealistic battle between the army of the undead (also called white walkers) and the army of living humans. George has decided to fix it, by writing the story in the best possible way: using math.

Suppose that the army of the undead has w white walkers and the army of the living has h humans. Repeatedly, pick a creature at random and let it kill one of its enemies. Therefore, a walker is killed with probability h/(h+w), and a human is killed otherwise. If a walker dies, nothing else happens. If a human dies, however, it turns into a walker!

The battle ends when one of the armies loses all its warriors. Note that, for large numbers, when h = w humans clearly have a very small chance of victory, whereas when hw their chances are very high.

Help George figure out who should win the battle and how to keep it optimally interesting. In particular, given the number of walkers w, can you determine the minimum number of humans h so that the army of the living has at least a 50% chance of victory?

Input

Input consists of several cases, each with a w between 1 and 1015.

Output

For every w, print the minimum number of humans h so that an army of h humans will have at least a 1/2 probability of winning a battle against w white walkers. You are allowed to miss your answer by 1 unit. A special corrector will handle it.

Public test cases
  • Input

    1
    2
    10
    10
    10
    

    Output

    1
    3
    16
    15
    17
    
  • Information
    Author
    Ferran Alet and Félix Miravé
    Language
    English
    Official solutions
    C++
    User solutions
    C++