In recent years, the world has encountered many epidemic impacts caused by various viruses, COVID-19 has spread and mutated globally since its outbreak in 2019, causing global impact. Nucleic acid detection is an important means for the prevention and control of infectious diseases. Aiming at people who are susceptible to sudden and infectious diseases, considering the control of viral nucleic acid detection cost and completion time, a probabilistic group test optimization method based on the cost and time value is proposed. Firstly, different cost functions to express the pooling and testing costs are used, a probability group test optimization model that considers the pooling and testing costs is established, the optimal combination number of samples for nucleic acid testing is obtained, and the positive probability and the cost functions of the group testing on the optimization result are explored. Secondly, considering the impact of the detection completion time on epidemic control, the sampling ability and detection ability were incorporated into the optimization objective function, then a probability group testing optimization model based on time value is established. Finally, taking COVID-19 nucleic acid detection as an example, the applicability of the model is verified, and the Pareto optimal curve under the minimum cost and shortest detection completion time is obtained. The results show that under normal circumstances, the optimal combination number of samples for nucleic acid detection is about 10. Generally, 10 is used to calculate for the convenience of organization, arrangement and statistics, except for cases where there are special requirements for testing cost and detection completion time.