Balls

시간 제한3초메모리 제한1024 MB

요약
각 구슬 총 개수 C에 대해 앨리스의 승리 확률이 50%에 가장 가까워지는 파란 구슬 개수 B를 구한다.
난이도

어려움10점 중 8점

유형
확률, 동적 계획법, 수학, 조합론
정답자
아직 제출이 없습니다

문제

Alice and Bob are playing a game. They've got BB blue and RR red balls laid out before them. Alice has the first move, and after that, players alternate moves. Alice picks a random ball and removes it. Bob removes a single red ball.

Alice chooses her balls randomly with equal probability regardless of their color. It does not matter which red ball Bob removes.

The game ends when one of the two outcomes occurs:

  • there are no more blue balls --- Alice wins;
  • there are strictly more blue balls than there are red balls --- Bob wins.

Alice and Bob would like a balance of outcomes, and are curious as for what number of blue balls is necessary for a game of C=B+RC = B + R for the probability of Alice winning to be as close to 5050\\% as possible. In other words, they want to minimize the value ∣h−0.5∣\left| h - 0.5 \right|.

입력

The first line of the input file contains a single integer GG --- the number of games Alice and Bob plan to play (1≤G≤1051 \le G \le 10^5).

The following lines define the number of balls CC in each game(2≤C≤2⋅1052 \le C \le 2 \cdot 10^5), one line per game.

출력

For each game, print the number of blue balls necessary for the chance of Alice's victory to be as close as possible to 5050\\% in a separate line in the same order as in the input file.

예제1

  1. 예제 1

    입력
    5
    2
    3
    6
    7
    8
    
    예상 출력
    1
    1
    2
    1
    2