#P1069. Cell Culture Experiment

    ID: 12719 Type: Default 1000ms 256MiB

Cell Culture Experiment

Cell Culture Experiment

Dr. Hanks is a renowned expert in the BT (Bio-Tech) field. He is preparing for a cell experiment: culturing cell samples. He has N types of cells, numbered from 1 to N. For the ith type of cell, each cell divides into Si cells after 1 second, where Si is a positive integer. Dr. Hanks will choose exactly one cell of one type to put into a petri dish, and let it divide freely. After some time, he will distribute all the cells equally into M test tubes (without splitting any cell) such that each tube gets the same number of cells.

The number M is huge and can only be represented as a power: \[ M = m_1^{m_2} \] where both m1 and m2 are positive integers that can be stored in basic data types.

Since splitting a cell is not allowed, if at some moment the petri dish contains a number of cells that is not exactly divisible by M, Dr. Hanks must continue culturing until the cell count becomes divisible by M (or choose another cell type). To start the experiment as early as possible, once he selects a cell type for culture, he always stops culturing immediately when the number of cells exactly becomes divisible by M.

Your task is to determine which cell type should Dr. Hanks choose to achieve the earliest possible start of the experiment. More specifically, if for a given cell type with reproduction factor Si, the number of cells after t seconds is Sit, then t must be the smallest positive integer such that:

[ S_i^t \equiv 0 ; (\bmod; M). ]

If for a cell type the condition can never be met, then that cell type cannot be chosen. In case there are multiple viable cell types, output the one that achieves the condition in the least time. If there is a tie, output the one with the smallest index. If none can ever satisfy the requirement, output -1.

inputFormat

The first line contains three space-separated positive integers: N, m1, and m2, where M = m1m2.

The second line contains N space-separated positive integers: S1, S2, ..., SN, where Si is the division factor for the ith type of cell.

outputFormat

If there is at least one viable cell type, output two integers separated by a space: the chosen cell type's index (1-indexed) and the minimum number of seconds required (t). Otherwise, if no cell type can meet the requirement, output -1.

sample

3 2 3
1 2 4
3 2