Title Description
Description
Dr. Hanks is a leading expert in the field of BT (Bio-tech, Biotechnology). Now he is preparing for a cell experiment: culturing cell samples.
Dr. Hanks now has N species of cells, numbered from 1~n, and an I cell can be split into Si cells after 1 seconds (SI is a positive integer). Now he needs to pick one of the cells and put it in a petri dish and let it split up and grow. After a period of time, all the cells in the petri dish are evenly divided into m-Test tubes to form a M-sample for experimentation. Dr. Hanks's number of tubes is large, and the basic data type of a normal computer cannot store such a large m-value, but fortunately, M can always be represented as a m2 of M1, that is, M = m1^ m2, where m1,m2 are positive integers that the base data type can store.
Note that a single cell is not allowed to be split during the entire experiment, such as when there are 4 cells in a petri dish at some point, Dr. Hanks can divide them into 2 test tubes, 2 in each test tube, and then begin the experiment. But if there are 5 cells in the Petri dish, the doctor will not be able to divide them into 2 test tubes. At this point, the doctor can only wait for a period of time, so that cells continue to divide, so that the number can be divided evenly, or simply change another cell culture.
In order for the experiment to begin as early as possible, Dr. Hanks stopped cell culture and began experimenting when a cell was selected to be cultured, and the resulting cells were "just as evenly divided into m-tubes". Now the doctor wants to know which cell culture to choose, which can make the start time of the experiment earliest.
Enter a description
Input Description
There are three lines.
The first line has a positive integer N, which represents the number of cells.
The second line has two positive integer m1,m2, separated by a space, m1^ m2 that represents the total number of m in the test tube.
The third row has N positive integers, and the number of I SI indicates the number of cells that can be split into the same cells after 1 seconds.
Output description
Output Description
A total of one row, which is an integer that represents the minimum time (in seconds) from the start of culturing the cell to the beginning of the experiment.
If Dr Hanks chooses which cell does not satisfy the requirement, the output integer-1.
Sample input
Sample Input
1
2 1
3
Sample output
Sample Output
-1
Data range and Tips
Data Size & Hint
After 1 seconds, the cells split into 3, after 2 seconds, the cells split into 9, ..., and you can see that no matter how divided, the number of cells is odd, and therefore can never be divided into 2 test tubes.
Code:
var cup:array[1..30000,1..2] of Longint;
N,m1,m2,length,t,p,i,j,minest,max,k,si:longint;
F,flag:boolean;
Begin
READLN (n);
READLN (M1,M2);
Fillchar (cup,sizeof (cup), 0);
Length:=1;
T:=M1;
For i:=2 to 2000000000 do
Begin
If T=1 then break;
F:=false;
While T mod i=0 do
Begin
F:=true;
Inc (cup[length,2]);
T: = t div i;
End
If f then BEGIN cup[length,1]:=i; Inc (length); End
End
Dec (length);
For i:=1 to length do
cup[i,2]:=cup[i,2]*m2;
minest:=2000000000;
For I: = 1 to n do
Begin
Read (SI);
If Si=1 then continue;
Flag:=true;
max:=0;
For j:=1 to length do
Begin
k:=0;
While Si mod cup[j,1]=0 do
Begin
Si: = si div cup[j,1];
Inc (k);
End
If k=0 then begin Flag:=false; Break End
If cup[j,2] MoD k = 0 then p:= cup[j,2] Div k
else p:=cup[j,2] Div k +1;
If p > Max then max: = P;
End
If flag and (max<minest) then Minest:=max;
End
If minest=2000000000 then Writeln ('-1 ')
else Writeln (minest);
End.
Test instructions abstract is to seek (Cell[i]) ^k mod m1^m2=0 the smallest k value.
The m1^m2 decomposition factorization can, and then the number of each cell decomposition, compared to the number of factors, for a factor, m1^m2 times have and the latter is not, then this situation must be no solution, continue to enumerate the next cell number can, and both are sometimes, is to be the least of the latter factor to make up greater than or equal to the latter factor of the minimum power, the processing of each factor after taking the maximum value of the factor, use it to update the answer.
Note the special case when M1=1, encounter 1 skip directly.
"NOIP2009" third question • cell division