QOJ.ac

QOJ

実行時間制限: 6.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#18183. LCM Queries

統計

给你一个由 $n$ 个正整数组成的数组 $a$ 和 $q$ 次询问。

每次询问中,给你一个正整数 $x$。你需要输出 $\max_{i=1}^{n} [\text{lcm}(x, a_i)]$。

换句话说,求 $x$ 与 $a$ 中任意元素的最小公倍数(LCM)的最大值。

输入格式

第一行包含两个整数 $n, q$ ($1 \le n, q \le 5 \cdot 10^5$) — 数组 $a$ 的大小和询问的次数。

第二行包含 $n$ 个空格分隔的整数 $a_1, \dots, a_n$ ($1 \le a_i \le 10^6$) — 数组 $a$。

第三行包含 $q$ 个空格分隔的整数 $x_1, \dots, x_q$ ($1 \le x_i \le 10^6$) — 询问。

输出格式

输出单行,包含 $q$ 个空格分隔的整数 — 每次询问的答案。

我们强烈建议在此题中使用快速输入输出(fast I/O)。

样例

输入样例 1

5 5
6 4 1 10 8
5 6 7 8 20

输出样例 1

40 30 70 40 60

说明

在样例测试中,最优的数对分别为 $\text{lcm}(5, 8) = 40$、$\text{lcm}(6, 10) = 30$、$\text{lcm}(7, 10) = 70$、$\text{lcm}(8, 10) = 40$、$\text{lcm}(20, 6) = 60$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.