Title Description
Dr. Hanks is a leading expert in the field of BT (Bio-tech, Biotechnology). Now he's working on a cell for a real
Preparation: culturing cell samples.
Dr. Hanks now has N species of cells, numbered from 1~n, and an I cell can be split for 1 seconds
Si homogeneous cells (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,
to develop. After a period of time, all the cells in the petri dish are evenly divided into m-Test tubes to form a sample of M,
For experimentation. Dr. Hanks's number of tubes is large, and the basic data types of ordinary computers cannot store such a large
M-value, but fortunately, M can always be represented as the M2 of M1, i.e.
M = m1^m2
, of which m1,m2 are basic
A positive integer that the 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,
Dr. Hanks can divide them into 2 test tubes, 2 in each test tube, and then start the experiment. But if there's 5 in the Petri dish,
Cells, the doctor cannot divide them into 2 test tubes. At this point, the doctor can only wait for a period of time for the cells to follow
To divide, so that the number can be divided evenly, or simply change another cell culture.
In order to allow the experiment to begin as early as possible, Dr. Hanks in the cells that had been selected after the start of a cell "just
It is possible to stop cell culture and begin the experiment by averaging the M-tube. Now the doctor wants to know what kind of fine
Cell culture, can make the start time of the experiment earliest.
Input/output format
Input format:
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,
That means the total number of test tubes M = m1^m2.
The third line has N positive integers, and the number of I SI indicates that the first type of cells can be split into the same cells after 1 seconds.
Number.
output Format:
The output file cell.out a total of one line, an integer that represents the beginning of the culture of the cell to the beginning of the experiment.
The minimum time (in seconds).
If Dr Hanks chooses which cell does not satisfy the requirement, the output integer-1.
1#include <cstdio>2#include <cmath>3 structPRM4 {5 intx,t;6}m[10010];7 inta[10010];8 intMain ()9 {Ten inti,j,k,n,p,q,m1,m2,x,y,z,cntm,ans,t; One BOOLOK; Ascanf"%d",&n); -scanf"%d%d",&m1,&m2); -cntm=0; the for(i=2; m1!=1; i++) - if(m1%i==0) - { -cntm++; +m[cntm].x=i; - while(m1%i==0) + { Am[cntm].t++; atM1/=i; - } -m[cntm].t*=m2; - } -ans=-1; - for(i=1; i<=n;i++) inscanf"%d",&a[i]); - for(i=1; i<=n;i++) to { +p=0; -ok=1; the for(j=1; j<=cntm;j++) * if(a[i]%m[j].x==0) $ {Panax Notoginsengt=0; - while(a[i]%m[j].x==0) the { +A[i]/=m[j].x; At++; the } + if(m[j].t%t==0) t=m[j].t/T; - Elset=m[j].t/t+1; $ if(t>p) p=T; $ } - Else - { theok=0; - Break;Wuyi } the if(ok&& (ans==-1|| P<ans)) ans=p; - } Wuprintf"%d\n", ans); -}
The title can be transformed into the smallest integer solution of the equation ax=km1m2 (k is an integer). "I'm going to try and play the formula."
First, the M1 quality factor decomposition, and then each number of times are multiplied m2 is the problem of the M-factor decomposition results.
If the equation has a solution, then each factor that must be M1 is a factor, so that a after power can become a multiple of M1. On this basis, the number of times in each factor is the most difference (refers to a multiple) of a multiple, is the minimum value of x.
NOIP2009 Group cell division (number theory)--YHX