#P2723. [USACO3.1] 丑数 Humble Numbers

    ID: 1731 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索数学USACO平衡树枚举,暴力排序

[USACO3.1] 丑数 Humble Numbers

Description

Given a set of primes S={p1,p2,...,pk}S = \{ p_1, p_2, ..., p_k \}, consider the set of positive integers whose prime factors all belong to SS. This set includes p1p_1, p1×p2p_1 \times p_2, p1×p1p_1 \times p_1, p1×p2×p3p_1 \times p_2 \times p_3 ... (and others). This set is called the "humble numbers set" of SS. Note: We consider 11 not to be a humble number.

Your task is, given the set SS, to find the nn-th humble number in the humble numbers set. It is guaranteed that the answer fits in a 32-bit signed integer.

Supplement: The humble numbers are ordered from small to large. Each humble number is a product of numbers from the prime set. The nn-th humble number is the nn-th smallest positive integer that can be formed by multiplying numbers from the prime set (including a prime itself).

Input Format

  • The first line contains two integers, which are the size kk of the set SS and the given parameter nn.
  • The second line contains kk distinct integers, where the ii-th integer denotes pip_i.

Output Format

Output a single integer, the answer.

4 19
2 3 5 7
27

Hint

  • Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1k1001 \leq k \leq 100.

  • 1n1051 \leq n \leq 10^5.

  • 2pi<2312 \leq p_i < 2^{31}, and each pip_i is prime.

  • Notes

Problem translation from NOCOW.

USACO Training Section 3.1.

Translated by ChatGPT 5