#P15240. [NHSPC 2025] 解碼密鑰

[NHSPC 2025] 解碼密鑰

Problem Description

In a video game, a supercomputer called the “Central Core” controls the operation of the entire city. However, recently the Central Core was locked by a firewall made of malicious code, and the city has fallen into paralysis.

To break this firewall, you must enter a specific “unlock code”. This unlock code is not a simple number, but the nn-th “valid number”. The city has kk special servers, and the ii-th server comes with a unique key pip_i. Any positive integer that is divisible by at least one of these kk keys can be considered a “valid number”.

Given nn and p1,p2,…,pkp_1,p_2,\ldots ,p_k, your task is to find the nn-th “valid number”, use it as the unlock code, and enter it into the “Central Core” to save the city.

For example, if n=10n=10, k=3k=3, and the keys are 2,3,52, 3, 5, then the numbers divisible by 22, 33, or 55 are, in order, 2,3,4,5,6,8,9,10,12,14…2, 3, 4, 5, 6, 8, 9, 10, 12, 14\ldots. The 1010-th number is 1414, so the answer is 1414.

Input Format

$$\begin{aligned} &n \; k \\ &p_1 \; p_2 \; \dots \; p_k \end{aligned}$$
  • nn means you need to find the nn-th valid number.
  • kk means the number of keys.
  • pip_i means the value of the ii-th key.

Output Format

ansans
  • Output a positive integer ansans, representing the nn-th number that is divisible by at least one number among p1,p2,…,pkp_1,p_2,\ldots ,p_k.
10 3
2 3 5
14
5 2
4 6
16
1000000000 4
1806 1110 600 777767777
325960839000

Hint

Constraints

  • 1≤n≤1091 \le n \le 10^9.
  • 1≤k≤61 \le k \le 6。
  • $1 \le p_1\times p_2\times\cdots\times p_k \le 10^{18}$。
  • It is guaranteed that the required answer is ≤1018\le 10^{18}.
  • All input numbers are integers.

Scoring

This problem has four subtasks with the following constraints. Each subtask may contain one or more testdata files, and you will get the score for a subtask only if you answer all testdata in that subtask correctly.

Subtask Score Additional Input Constraints
1 2 It is guaranteed that the required answer is ≤106\le 10^{6}。
2 27 n≤10,k≤2n \le 10, k \le 2。
3 34 n≤105n \le 10^5。
4 37 No additional constraints.

Translated by ChatGPT 5