QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 32 MB 總分: 40

#17067. 埃拉托斯特尼筛法

统计

埃拉托斯特尼筛法(Sieve of Eratosthenes)是一种用于寻找所有小于等于 $N$ 的素数的著名算法。该算法的步骤如下:

  1. 写下 $2$ 到 $N$ 之间(包含 $2$ 和 $N$)的所有整数。
  2. 找到未被划掉的最小整数,记为 $P$;$P$ 是一个素数。
  3. 划掉 $P$ 以及所有尚未被划掉的 $P$ 的倍数。
  4. 如果还有数未被划掉,则返回步骤 2。

编写一个程序,在给定 $N$ 和 $K$ 的情况下,找出第 $K$ 个被划掉的整数。

输入格式

输入包含两个整数 $N$ 和 $K$($2 \le K < N \le 1000$)。

输出格式

输出第 $K$ 个被划掉的数。

样例

输入 1

7 3

输出 1

6

输入 2

15 12

输出 2

7

输入 3

10 7

输出 3

9

说明

在第三个样例中,我们依次划掉的数字为 $2, 4, 6, 8, 10, 3, 9, 5$ 和 $7$。第七个被划掉的数字是 $9$。

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.