Fortune Wheel

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

요약
n개 칸의 바퀴에서 x번 칸에서 시작해 K개의 고정 점프와 무작위 칸으로 이동하는 수단을 써서 0번 칸에 도달하는 최소 기대 횟수를 구한다.
난이도

어려움10점 중 8점

유형
그래프, 정렬, 확률, 최단 경로
정답자
아직 제출이 없습니다

문제

A Fortune Wheel has nn sectors numbered from 00 to n−1n - 1 in clockwise order. It also has an arrow pointing at one of the sectors. Right now, it is pointing at sector xx.

You are very good at spinning the Wheel. More specifically, you have learned KK distinct power spins, characterized by their power k_1,k_2,…,k_Kk\_1, k\_2, \ldots, k\_K. A power spin with power pp means that you spin the Wheel with such power that the arrow would turn exactly pp sectors clockwise: formally, from sector yy, it would turn to sector (y+p) mod n(y + p) \bmod n. Also, you can do a common spin: spin the Wheel so that the arrow would be pointing at a uniformly random sector. Your skills allow you to do any number of spins any number of times in any order.

You want the arrow to be pointing at sector 00 as soon as possible. Find the expected value of the number of spins required to do so in an optimal strategy. A strategy is considered optimal if it minimizes the said expected value.

입력

The first line contains three integers: the number of sectors nn, the starting sector of the arrow xx, and the number of power spins KK (1≤n≤1051 \leq n \leq 10^5; 0≤x≤n−10 \leq x \leq n - 1; 1≤K≤5001 \leq K \leq 500).

The second line contains kk distinct integers k_1,k_2,…,k_Kk\_1, k\_2, \ldots, k\_K (1≤k_i≤n1 \leq k\_i \leq n).

출력

Print a line containing two integers pp and qq (0≤p0 \leq p; 0<q0 < q): numerator and denominator of an irreducible fraction p/qp/q which is the expected value of the number of spins. It can be proved that the answer can be represented in this way.

예제2

  1. 예제 1

    입력
    6 3 2
    2 4
    
    예상 출력
    8 3
    
  2. 예제 2

    입력
    5 4 1
    1
    
    예상 출력
    1 1