#P13417. [COCI 2012/2013 #4] DLAKAVAC

    ID: 15291 远端评测题 2000ms 32MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>动态规划 DP数学递推2012倍增递归矩阵加速COCI(克罗地亚)

[COCI 2012/2013 #4] DLAKAVAC

题目描述

In the faraway city of Xanadu, a flu epidemic has broken out, caused by a strain known as hairy flu. There are MM people living in the city, each resident having a unique personal ID number from the range of 00 to M1M - 1, inclusive. Infection with this strain lasts exactly one day, and a person can catch it multiple times per season (since it mutates too quickly for lasting immunity).

On the first day of the epidemic, the flu was brought from another faraway country by a group of residents nicknamed "init-patients", whose ID numbers are known. The flu's spread is based on them. Each following day, a resident with ID number pp will catch the flu iff there exists a resident with ID aa who was infected the previous day, as well as an init-patient with ID bb, such that:

(a×b)modM=p.(a \times b) \bmod M = p.

The numbers aa and bb need not be distinct. For example, consider a case where there are 101101 people in the town, and the init-patients are 55 and 5050. On the first day, the init-patients are infected by definition. On the second day, the residents infected are 2525, 4848 (250mod101250 \mod 101), and 7676 (2500mod1012500 \mod 101). On the third day, one of the infected patients is 7777, since (48×50)mod101=77(48 \times 50) \mod 101 = 77.

Who will catch the flu on the KK-th day?

输入格式

The first line of input contains three positive integers, KK, MM, and NN (1K10181 \leq K \leq 10^{18}, 3M15003 \leq M \leq 1500, N<MN < M).

The second line of input contains NN space-separated nonnegative integers, the personal ID numbers of residents who were infected on the first day (the init-patients). These numbers are unique, increasing, and do not exceed M1M - 1.

输出格式

The first and only line of output must contain the personal ID numbers of residents infected with flu on the KK-th day, given space-separated and in increasing order.

1 100 3
1 2 3 
1 2 3
2 100 3
1 2 3
1 2 3 4 6 9
10 101 2
5 50
36 44 57 65