Greek Casino

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

요약
1부터 N까지 정수에 대한 가중치가 주어질 때, 슬롯 1에서 시작해 LCM이 N을 넘기 전까지 이동하는 횟수의 기댓값을 구한다.
난이도

어려움10점 중 8점

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

문제

Since the early civilizations, humankind has enjoyed games of chance. Even the ingenious Greeks, known for their groundbreaking concept of the least common multiple (LCM), couldn’t resist a good gamble.

Inspired by this mathematical marvel, folks in Athens devised a unique betting system: after purchasing a ticket, a participant would receive a random number of coins. To determine this number, there are N≥3N ≥ 3 ordered slots numbered from 11 to NN. A token is initially placed at slot 11, and the following steps are repeated:

  • Let $xv be the number of the slot where the token is currently located.
  • Generate a random integer yy between 11 and NN, and compute zz the LCM of xx and yy.
  • If z>Nz > N, the procedure ends.
  • Otherwise, the token is moved to slot zz, and the participant receives one coin.

As it is well known, the house always wins: the casino employs a particular probability distribution for generating random integers, so as to ensure a profitable outcome.

The casino owner is constantly seeking to optimize the betting system’s profitability. You, an AI designed to aid in such tasks, are given NN and the probability distribution. Determine the expected total number of coins awarded to a participant.

입력

The first line contains an integer NN (3≤N≤1053 ≤ N ≤ 10^5) indicating the number of slots.

The second line contains NN integers W_1,W_2,…,W_NW\_1, W\_2, \dots , W\_N (1≤W_i≤10001 ≤ W\_i ≤ 1000 for i=1,2,…,Ni = 1, 2, \dots , N), representing that the probability of generating ii is W_i/(∑_jW_j)W\_i/ \left( \sum\_j{W\_j} \right), that is, the probability of generating ii is the relative weight of W_iW\_i with respect to the sum of the whole list W_1,W_2,…,W_NW\_1, W\_2, \dots , W\_N.

출력

Output a single line with the expected total number of coins awarded to a participant. The output must have an absolute or relative error of at most 10−910^{-9}. It can be proven that the procedure described in the statement ends within a finite number of iterations with probability 11, and that the expected total number of coins is indeed finite.

예제2

  1. 예제 1

    입력
    3
    1 1 1
    
    예상 출력
    3.5
    
  2. 예제 2

    입력
    3
    1 1 2
    
    예상 출력
    3.6666666667